help with FtpWebRequest

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/ =-
 
B

bruce barker

because you only read the first 64k (default buffer size) of the file.
you should loop reading and writing.

-- bruce (sqlwork.com)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top