以下是代码:
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
问题在于,当我实际从我的源下载文件时,然后将其上传到我的目的地。文件中唯一的东西是一段文字,上面写着“System.IO.Streamreader”我在这里做错了什么?
答案 0 :(得分:0)
我没有看到任何突出的错误。
如果这一行,您获得的“System.IO.Streamreader”将是预期的结果:
ftpStreamWriter.Write(New StreamReader(responseStream).ReadToEnd)
实际上是这样的:
ftpStreamWriter.Write(New StreamReader(responseStream))
你可以仔细检查你正在测试的版本中是否存在.ReadToEnd,如果编译好了吗?
假设这不是问题,如果你这样做会发生什么:
dim sToWrite as String = New StreamReader(responseStream).ReadToEnd
debug.write(sToWrite)
ftpStreamWriter.Write(sToWrite)
检查该字符串是否至少会告诉您是否正确读取数据。
你没有包含很多类型定义所以我不得不猜测类型,但是你可能想尝试启用option strict来查看它是否捕获了你没注意到的类型问题。