B
brian
The following code fails when, and only when the transmitted file is larger than 64K. Any ideas what is wrong. The files does send but any file larger than 64k gets truncated to exactly 64KB.
No exception occurs. If I send the file using an FTP client lile FileZilla, the file sends correctly. Point being it does seem it's a problem in the code.
If there is a better group for this please advise.
Thanks
Public Sub uploadFileUsingFTP(ByVal CompleteFTPPath As String, ByVal CompleteLocalPath As String, Optional ByVal UName As String = "", Optional ByVal PWD As String = "")
'This fuction uses four parameters,
' CompleteFTPPath and filename of remote site
' CompleteLocalPath and filename on local site
' Third and Fourth parameters are UName and PWD used to validate network crediential.
Try
Dim reqObj As FtpWebRequest = WebRequest.Create(CompleteFTPPath)
reqObj.Method = WebRequestMethods.Ftp.UploadFile
reqObj.KeepAlive = True
reqObj.Credentials = New NetworkCredential(UName, PWD)
reqObj.Proxy = New WebProxy()
reqObj.UseBinary = True
'FileStream object read file from Local Drive
Dim streamObj As FileStream = File.OpenRead(CompleteLocalPath)
'Store File in Buffer
Dim buffer(streamObj.Length) As Byte
'Read File from Buffer
streamObj.Read(buffer, 0, buffer.LongLength - 1)
'Close FileStream Object Set its Value to nothing
streamObj.Close()
streamObj = Nothing
'Upload File to ftp://localHost/ set its object to nothing
reqObj.GetRequestStream().Write(buffer, 0, buffer.LongLength - 1)
reqObj = Nothing
Catch ex As Exception
tbmsg.Text = ex.Message
End Try
End Sub
--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
No exception occurs. If I send the file using an FTP client lile FileZilla, the file sends correctly. Point being it does seem it's a problem in the code.
If there is a better group for this please advise.
Thanks
Public Sub uploadFileUsingFTP(ByVal CompleteFTPPath As String, ByVal CompleteLocalPath As String, Optional ByVal UName As String = "", Optional ByVal PWD As String = "")
'This fuction uses four parameters,
' CompleteFTPPath and filename of remote site
' CompleteLocalPath and filename on local site
' Third and Fourth parameters are UName and PWD used to validate network crediential.
Try
Dim reqObj As FtpWebRequest = WebRequest.Create(CompleteFTPPath)
reqObj.Method = WebRequestMethods.Ftp.UploadFile
reqObj.KeepAlive = True
reqObj.Credentials = New NetworkCredential(UName, PWD)
reqObj.Proxy = New WebProxy()
reqObj.UseBinary = True
'FileStream object read file from Local Drive
Dim streamObj As FileStream = File.OpenRead(CompleteLocalPath)
'Store File in Buffer
Dim buffer(streamObj.Length) As Byte
'Read File from Buffer
streamObj.Read(buffer, 0, buffer.LongLength - 1)
'Close FileStream Object Set its Value to nothing
streamObj.Close()
streamObj = Nothing
'Upload File to ftp://localHost/ set its object to nothing
reqObj.GetRequestStream().Write(buffer, 0, buffer.LongLength - 1)
reqObj = Nothing
Catch ex As Exception
tbmsg.Text = ex.Message
End Try
End Sub
--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-