Click here to Skip to main content
15,918,516 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this code copy only file with 0 bytes. Please Help

Private Sub Upload(ByVal filePath As String, ByVal fileName As String)

        ftpServerIP = " Documents"
        ftpUserID = "h"
        ftpPassword = "Har"

        Dim reqFTP As FtpWebRequest
            'filePath = <<The full path where the file is to be created.>>,
            'fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
            Dim outputStream As New FileStream(filePath + "\" + fileName, FileMode.Create)

            reqFTP = DirectCast(FtpWebRequest.Create(New Uri("ftp://" + ftpServerIP + "/" + fileName)), FtpWebRequest)
            reqFTP.Method = WebRequestMethods.Ftp.AppendFile
            reqFTP.UseBinary = True
            reqFTP.Credentials = New NetworkCredential(ftpUserID, ftpPassword)
            Dim response As FtpWebResponse = DirectCast(reqFTP.GetResponse(), FtpWebResponse)
            Dim ftpStream As Stream = response.GetResponseStream()
            Dim cl As Long = response.ContentLength
            Dim bufferSize As Integer = 2048
            Dim readCount As Integer
            Dim buffer As Byte() = New Byte(bufferSize - 1) {}

            readCount = ftpStream.Read(buffer, 0, bufferSize)
            While readCount > 0
                outputStream.Write(buffer, 0, readCount)
                readCount = ftpStream.Read(buffer, 0, bufferSize)
            End While

            ' MessageBox.Show("Download Complete");
        Catch ex As Exception
        End Try
    End Sub
Updated 3-Nov-11 18:43pm

ftpServerIP = " Documents"

       Dim clsRequest As System.Net.FtpWebRequest = _
           DirectCast(FtpWebRequest.Create(New Uri("ftp://" + ftpServerIP + "/" + fileName)), FtpWebRequest)
       clsRequest.Credentials = New System.Net.NetworkCredential("userid", "password")
       clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile

       ' read in file...
       Dim bFile() As Byte = System.IO.File.ReadAllBytes(filePath + "\" + fileName)

       ' upload file...
       Dim clsStream As System.IO.Stream = clsRequest.GetRequestStream()
       clsStream.Write(bFile, 0, bFile.Length)
Share this answer
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900