我已经好几天了。 GetRequestStream()每次都会失败,即使设置并验证为null也是如此。这是奇怪的事情,它只发生在5台机器中的3台,我找不到有什么区别。有人有线索吗?
Public Sub UploadFtpFile_Simple(PushFileName As String)
Me.CreateFile(PushFileName, Me.FetchData())
Dim CompleteFTPPath As String = "ftp://ftp.site.com/Filename.csv"
Dim CompleteLocalPath As String = PushFileName
Dim UName As String = Site1UserName
Dim PWD As String = Site1Pass
Dim reqObj As FtpWebRequest = DirectCast(WebRequest.Create(CompleteFTPPath), FtpWebRequest)
'reqObj.Proxy = GlobalProxySelection.GetEmptyWebProxy()
'reqObj.Proxy = Nothing
'reqObj.Proxy = WebRequest.DefaultWebProxy
'reqObj.Proxy = New System.Net.WebProxy()
reqObj.Method = WebRequestMethods.Ftp.UploadFile
reqObj.Credentials = New NetworkCredential(UName, PWD)
Dim streamObj As FileStream = File.OpenRead(CompleteLocalPath)
Dim buffer(streamObj.Length) As Byte
streamObj.Read(buffer, 0, buffer.Length)
streamObj.Close()
streamObj = Nothing
Try
If DEBUGMODE Then
reqObj.GetRequestStream()
Else
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length)
End If
Console.WriteLine("GetRequestStream Success")
Catch ex As Exception
Console.WriteLine("GetRequestStream failure - {0} Stack Track:{1}", ex.Message, ex.StackTrace)
End Try
reqObj = Nothing
End Sub