sudha karpak

sudha karpak

  • NA
  • 10
  • 0

ftpwebrequest

Nov 27 2006 12:11 AM

I have met a intersting problem here,but i am unable to solve it.  I used the ftpwebrequest
to upload files to the ftpserver path.when a small bytes file like a text file of 1000 bytes is
uploaded using this source code,its smoothly uploads the file to the customer path.when the
file bytes is more than 5,000 bytes,only 4300 bytes are uploaded in the serverpath.The remaining
bytes are discarded.i.e the uploaded file size in the ftp server path is not same as the file uploaded from the local path.I have very much confused with it.

This is the code sample,

Dim ftp As System.Net.FtpWebRequest = CType(WebRequest.Create(Trim(topath) & fil.Name), FtpWebRequest)
                    ftp.Method = System.Net.WebRequestMethods.Ftp.UploadFile
                    ftp.UseBinary = True
                    ftp.Credentials = New System.Net.NetworkCredential(Trim(username), Trim(password))
                    ftp.KeepAlive = False
                    Dim strreader As New StreamReader(fil.Path)
                    Dim filecontent() As Byte
                    filecontent = System.Text.Encoding.UTF8.GetBytes(strreader.ReadToEnd)
                  ' ------------

                    strreader.Close()
                    ftp.ContentLength = filecontent.Length
                    Dim requeststream As Stream = ftp.GetRequestStream
                    requeststream.Write(filecontent, 0, filecontent.Length)
                    requeststream.Close()
                    Dim response As System.Net.FtpWebResponse = CType(ftp.GetResponse, FtpWebResponse)

                 After i debug the code,i found that the filecontent byte array holds the value minumum than the actual bytes of the localfile to be uploaded.The streamreader reads only the minumum values of the file content.The remaining file content are discarded by the streamreader.
How do i overcome the problem?
I hope to get a quick reply for this,
Thanks in advance