File not uploaded to secure website

  • Thread starter Thread starter BobStin
  • Start date Start date
B

BobStin

Guest
I have uploaded files through the other companys website manually, but I cannot upload files (3.5MB in size) using my code. I dont get any error codes. This is my first time doing this. Here is my code.





Dim




strUID As String = "myid"



Dim strPWD As String = "mypswd






Dim strFTPServer As String













Try





Dim WRequest As HttpWebRequest






Dim WResponse As HttpWebResponse



WRequest =


DirectCast(HttpWebRequest.Create(strFTPServer), HttpWebRequest)





Set the username and the password.



WRequest.Credentials =


New NetworkCredential(strUID, strPWD)


WRequest.UnsafeAuthenticatedConnectionSharing =


True



WRequest.AllowWriteStreamBuffering =


True



WRequest.PreAuthenticate =


True



WRequest.UserAgent =


"Upload Test"



WRequest.Method =


"HEAD"



WRequest.Timeout = 600000

WResponse =


DirectCast(WRequest.GetResponse(), HttpWebResponse)


WResponse.Close()




Make the real request.



WRequest =


DirectCast(HttpWebRequest.Create(strFTPServer), HttpWebRequest)





Set the username and the password.



WRequest.Credentials =


New NetworkCredential(strUID, strPWD)


WRequest.UnsafeAuthenticatedConnectionSharing =


True



WRequest.AllowWriteStreamBuffering =


False



WRequest.PreAuthenticate =


True



WRequest.UserAgent =


"Upload Test"



WRequest.Method =


"POST"



WRequest.Timeout = 600000




Dim ReadIn As New FileStream(WellnessFileName, FileMode.Open, FileAccess.Read)





File.Open(WellnessFileName, FileMode.Open)






Move to the start of the file.



ReadIn.Seek(0,


SeekOrigin.Begin)


WRequest.ContentLength = ReadIn.Length




Set the content length header to the size of the file.






Dim FileData As [Byte]() = New [Byte](ReadIn.Length - 1) {}





Read the file in 2 KB segments.






Dim DataRead As Integer = 0





Dim tempStream As Stream = WRequest.GetRequestStream()


tempStream.WriteTimeout = 600000




Do



DataRead = ReadIn.Read(FileData, 0, 4096)




If DataRead > 0 Then






we have data



tempStream.Write(FileData, 0, DataRead)




Clear the array.






Array.Clear(FileData, 0, 4096)





End If






Loop While DataRead > 0





Read your response data here.



WResponse =


DirectCast(WRequest.GetResponse(), HttpWebResponse)





Dim strres As String = WResponse.StatusCode.ToString()





Close all streams.



WRequest =


Nothing



ReadIn.Close()

tempStream.Close()

WResponse.Close()

tempStream.Dispose()

ReadIn.Dispose()

WResponse.Dispose()




Catch ex As WebException






Console.WriteLine(ex.ToString())





Catch ex As Exception






Console.WriteLine(ex.ToString())





End Try

Continue reading...
 
Back
Top