【问题标题】:Visual Basic FTP File Zilla Server?Visual Basic FTP Filezilla 服务器?
【发布时间】:2016-08-07 10:22:04
【问题描述】:

我正在使用此代码:

Imports System.IO
Imports System.Net

Public Class sendftp

Public Function UploadFileToFtp(ByVal f As String, ByVal host As String, ByVal username As String, ByVal password As String, ByVal folderToUploadTo As String) As Boolean
    Try
        'create an FtpRequest object, holds the value of the path you are trying to reach
        Dim ftpRequest As FtpWebRequest = DirectCast(FtpWebRequest.Create(New Uri(host & "/" & Path.GetFileName(folderToUploadTo))), FtpWebRequest)

        'pass in our login credentials
        ftpRequest.Credentials = New NetworkCredential(username, password)

        'set the method to Upload, since we're uploading a file
        ftpRequest.Method = WebRequestMethods.Ftp.UploadFile


        'don't use passive mode
        ftpRequest.UsePassive = True
        'unless we're uploading a file like an image
        'we need to set this to false as we're not uploading
        'binary data
        ftpRequest.UseBinary = True
        'set KeepAlive to false
        ftpRequest.KeepAlive = False

        'now create a new FileStream, then open the file we're uploading
        'this allows us to get the size of the file for our buffer
        Dim stream As FileStream = File.OpenRead(f)
        'create a byte[] array buffer the size of the file
        'we're uploading
        Dim buffer As Byte() = New Byte(stream.Length - 1) {}

        'read in our file into the FileStream
        stream.Read(buffer, 0, buffer.Length)
        'close the FileStream
        stream.Close()

        'create a new stream, this will be used to write to the
        'FTP server
        Dim requestStream As Stream = ftpRequest.GetRequestStream()
        'write the data to the FTP server
        requestStream.Write(buffer, 0, buffer.Length)
        'close the stream
        requestStream.Close()
        'since we made it this far return true
        Return True
    Catch ex As Exception
        'something went wront so let the user know
        MessageBox.Show("Error uploading file: " + ex.Message, "Upload Error")
        'return false
        Return False
    End Try
End Function
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    UploadFileToFtp("C:\file.txt", "ftp://ftp.drivehq.com", "**user**", "**password**", "new.txt")



End Sub
End Class

而且它有效。

但是我想使用我的 FileZilla 服务器,所以我编辑了 ftp url:

UploadFileToFtp("C:\file.txt", "ftp://localhost", "**user**", "**password**", "new.txt")

但我收到此错误:?

远程服务器返回错误:(550) 文件不可用(例如,找不到文件,无法访问)。

我想不通,有什么想法吗?

【问题讨论】:

    标签: vb.net


    【解决方案1】:

    原来是我通过 ftp 服务器设置修复的权限...抱歉给我带来的不便

    【讨论】:

      猜你喜欢
      • 2011-09-19
      • 1970-01-01
      • 2011-09-13
      • 2014-08-25
      • 2018-10-21
      • 2015-02-12
      • 2021-06-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多