Here's the code:
response.Close()
ftpWebRequest = WebRequest.Create(ftp_location & dr("FILE_LOCATION").ToString.Replace("~", ""))
ftpWebRequest.Credentials = New NetworkCredential(ftp_user, ftp_pw)
ftpWebRequest.Method = WebRequestMethods.Ftp.UploadFile
ftpWebRequest.UseBinary = True
ftpSourceRequest = WebRequest.Create(ftp_source & dr("FILE_LOCATION").ToString.Replace("~", ""))
ftpSourceRequest.Credentials = New NetworkCredential(ftp_user, ftp_pw)
ftpSourceRequest.Method = WebRequestMethods.Ftp.DownloadFile
ftpSourceRequest.UseBinary = True
Try
ftpSourceResponse = ftpSourceRequest.GetResponse()
Dim t As System.Net.FtpStatusCode = ftpSourceResponse.StatusCode
Dim responseStream As IO.Stream = ftpSourceResponse.GetResponseStream
ftpStreamWriter = New StreamWriter(ftpWebRequest.GetRequestStream())
ftpStreamWriter.Write(New StreamReader(responseStream).ReadToEnd)
dr("STATUS") = "OK"
dr.AcceptChanges()
ftpStreamWriter.Close()
response.Close()
ftpSourceResponse.Close()
Catch ex4 As Exception
response.Close()
ftpSourceResponse.Close()
End Try
The problem is that when I actually download the file from my source, then upload it to my destination. The only thing in the file is a piece of text that says "System.IO.Streamreader" What am I doing wrong here?
I didn't see anything that stands out as wrong.
The "System.IO.Streamreader" you are getting would be the expected result if this line:
ftpStreamWriter.Write(New StreamReader(responseStream).ReadToEnd)
was actually like this:
ftpStreamWriter.Write(New StreamReader(responseStream))
Can you double check that .ReadToEnd was in there in the version you are testing and that if compiled ok?
Assuming that isn't the issue, what happens if you do:
dim sToWrite as String = New StreamReader(responseStream).ReadToEnd
debug.write(sToWrite)
ftpStreamWriter.Write(sToWrite)
Checking that string will at least tell you if you are reading the data correctly.
You don't include a lot of the type definitions so I had to guess on the types, but you might want to try turning on option strict to see if it catches type issues you didn't notice.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.