2010-11-15 255 views
0

下面的代碼:ASP.net:FTP問題,試圖從一個FTP移動ASPX文件到另一個

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

我沒有看到任何脫穎而出的錯誤。

的 「就是System.IO.StreamReader」 你正在將是預期的結果,如果這條線:

ftpStreamWriter.Write(New StreamReader(responseStream).ReadToEnd) 

竟是這樣的:

ftpStreamWriter.Write(New StreamReader(responseStream)) 

你能仔細檢查.ReadToEnd在那裏,你正在測試的版本,如果編譯OK?

假設不是問題,如果你這樣做會發生什麼:

dim sToWrite as String = New StreamReader(responseStream).ReadToEnd 
debug.write(sToWrite) 
ftpStreamWriter.Write(sToWrite) 

檢查字符串至少會告訴你,如果你正確地讀取數據。

你不包括很多類型定義的,所以我猜的類型,但你可能想嘗試打開選項嚴格,看看是否能抓住鍵入你沒注意到的問題。

+0

其實,這也正是它是什麼。不知何故,ReadToEnd的被覆蓋。調查源頭控制以找到罪魁禍首。 – jlrolin 2010-11-15 22:04:03

相關問題