1

I've been at this for days. The GetRequestStream() fails every time, even when set and verified as null. Here is the strange thing, it only happens on 3 out of 5 machines and I can't locate what the difference is. Anybody have a clue?

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
Joseph Norris
  • 368
  • 1
  • 11
  • I even added Dim proxy As IWebProxy = CType(reqObj.Proxy, IWebProxy) If Not proxy Is Nothing Then Console.WriteLine("Proxy: {0}", proxy.GetProxy(reqObj.RequestUri)) Else Console.WriteLine("Proxy is null; no proxy will be used") End If Its null every time. – Joseph Norris Jun 08 '16 at 21:08
  • [Enable logging](http://stackoverflow.com/q/9664650/850848) and show us a log from both working and non-working machine. – Martin Prikryl Jun 09 '16 at 03:33

0 Answers0