下载一个ftp文件

时间:2014-03-16 17:25:24

标签: asp.net ftp

我正在尝试从我的在线网络服务器下载ftp文件。该文件位于ftp100-0中,是该文件中唯一的文件。错误代码说明:

The requested URI is invalid for this FTP command.

这是我的代码:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
    ' Get the object used to communicate with the server.
    Dim request As FtpWebRequest = DirectCast(WebRequest.Create("ftp://www.mysite.com/"), FtpWebRequest)
    request.Method = WebRequestMethods.Ftp.DownloadFile

    ' This example assumes the FTP site uses anonymous logon.
    request.Credentials = New NetworkCredential("ftp100-0", "password")

    Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)

    Dim responseStream As Stream = response.GetResponseStream()
    Dim reader As New StreamReader(responseStream)
    Console.WriteLine(reader.ReadToEnd())

    Console.WriteLine("Download Complete, status {0}", response.StatusDescription)

    reader.Close()
    response.Close()
End Sub

1 个答案:

答案 0 :(得分:0)

尝试从网络浏览器提供的网址,以确保其正确无误。 URL中缺少文件名。