Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > help with FtpWebRequest

Reply
Thread Tools

help with FtpWebRequest

 
 
brian
Guest
Posts: n/a
 
      03-06-2009
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/ =-

 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      03-07-2009
because you only read the first 64k (default buffer size) of the file.
you should loop reading and writing.

-- bruce (sqlwork.com)

brian wrote:
> 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/ =-
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with FtpWebRequest (UploadFile status/progress) Dan ASP .Net 0 01-07-2010 06:10 PM
FTPWebRequest failing - URGENT BizWorld ASP .Net 1 06-15-2007 07:34 PM
Passing DefaultCredentials to an FtpWebRequest =?Utf-8?B?QmlsbA==?= ASP .Net 0 03-21-2007 08:45 AM
FTPWebRequest File.ReadOpen Could Not Find File jlacefie@gmail.com ASP .Net 2 02-12-2007 09:41 PM
How to keep session in FtpWebRequest Darqer ASP .Net 1 11-06-2006 05:38 PM



Advertisments