download via ftp

pettrer

Well-known member
Joined
Sep 5, 2008
Messages
92
Programming Experience
10+
Hi,

There is something wrong in this short code snippet of mine:

VB.NET:
Friend Sub RetrieveFtpFile(ByVal ftpFileUri As String, ByVal destFilePath As String)
fwr = FtpWebRequest.Create("ftp://" & ftpFileUri)
fwr.Method = WebRequestMethods.Ftp.DownloadFile
fwr.Credentials = New NetworkCredential("xx", "yy")
Dim reader As New FileStream(destFilePath, FileMode.Create)
Dim sr As Stream = fwr.GetResponse().GetResponseStream()
Dim buffer(1024) As Byte
Dim bytesRead As Integer = sr.Read(buffer, 0, 1024)
While bytesRead <> 0
    reader.Write(buffer, 0, bytesRead)
    bytesRead = sr.Read(buffer, 0, 1024)
End While
reader.Flush()
reader.Close()
sr.Close()

The problem is that the row starting with sr = ... yields the following error: "The remote server returned an error: (550) File unavailable (e.g., file not found, no access)."

If I open Internet Explorer and type ftp://www...name.jpg (the equivalent of "ftp://" & ftpFileUri above) I get a login window, and I use the user name and password which are called xx and yy above. Then I see the jpg in the browser. In other words, there must be something else that's wrong but I have no idea what it might be.

Please help - I've struggled too many hours with this!

/Pettrer
 
Back
Top