T
ThatsIT.net.au
I recently made a ftp upload, and now I am trying to make a ftp download, my
problem is the file is always corrupted. I can upload the file no
problems, I can download text files, but I cant download images. I have a
217 kb png image, when I download it it is corrupted and it is 391 kb in
size.
any ideas
Private Sub downloadFileFromFTP(ByVal fileName)
Dim ftpUrl As Uri = New Uri("ftp://192.168.0.2/" & fileName)
Try
Dim ftpReq As FtpWebRequest =
WebRequest.Create(ftpUrl.AbsoluteUri)
ftpReq.Proxy = Nothing
ftpReq.Method = WebRequestMethods.Ftp.DownloadFile
ftpReq.Credentials = New NetworkCredential("au\mosley",
"faron&missy")
ftpReq.UseBinary = True
Dim ftpResp As FtpWebResponse = ftpReq.GetResponse
Dim ftpRespStream As Stream = ftpResp.GetResponseStream
Dim reader As StreamReader
reader = New StreamReader(ftpRespStream, True)
Dim sw As StreamWriter = New StreamWriter("c:\test\ftp\" &
fileName)
sw.AutoFlush = True
sw.Write(reader.ReadToEnd)
reader.Close()
sw.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub
problem is the file is always corrupted. I can upload the file no
problems, I can download text files, but I cant download images. I have a
217 kb png image, when I download it it is corrupted and it is 391 kb in
size.
any ideas
Private Sub downloadFileFromFTP(ByVal fileName)
Dim ftpUrl As Uri = New Uri("ftp://192.168.0.2/" & fileName)
Try
Dim ftpReq As FtpWebRequest =
WebRequest.Create(ftpUrl.AbsoluteUri)
ftpReq.Proxy = Nothing
ftpReq.Method = WebRequestMethods.Ftp.DownloadFile
ftpReq.Credentials = New NetworkCredential("au\mosley",
"faron&missy")
ftpReq.UseBinary = True
Dim ftpResp As FtpWebResponse = ftpReq.GetResponse
Dim ftpRespStream As Stream = ftpResp.GetResponseStream
Dim reader As StreamReader
reader = New StreamReader(ftpRespStream, True)
Dim sw As StreamWriter = New StreamWriter("c:\test\ftp\" &
fileName)
sw.AutoFlush = True
sw.Write(reader.ReadToEnd)
reader.Close()
sw.Close()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
End Sub