0

这是代码:

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”我在这里做错了什么?

4

1 回答 1

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)

检查该字符串至少会告诉您是否正确读取数据。

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.

于 2010-11-15T21:34:23.347 回答