Click here to Skip to main content
15,886,199 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

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


        ftpServerIP = "192.160.0.10/Employee Documents"
        ftpUserID = "h"
        ftpPassword = "Har"

        Dim reqFTP As FtpWebRequest
        Try
            '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

            ftpStream.Close()
            outputStream.Close()
            ' MessageBox.Show("Download Complete");
            response.Close()
        Catch ex As Exception
            'MessageBox.Show(ex.Message)
        End Try
    End Sub
Posted
Updated 3-Nov-11 18:43pm
v3

VB
ftpServerIP = "155.166.0.10/Employee 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)
       clsStream.Close()
       clsStream.Dispose()
 
Share this answer
 
v3
 
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