Send files to server using FTP

remya1000

Well-known member
Joined
Mar 29, 2007
Messages
122
Programming Experience
Beginner
how can i send a new file to a server using FTP in VB.NET.

i need to try sending new files to server using FTP. after sending i can delete from server,rename,update the file etc.

first i need to make a connection to server and try sending new files(that's file not present in server) to server.

anyidea how can i make a connection and send file to server.

if you know how to do this, please help me. if you can send any examples that will be very help for me.

thanks in advance.
 
i check that link you send. it really helped me lot to send data to server.

i'm able to send files to server using FTP.

if the file is big, then it will take some time to complete the sending process to server.or if we were sending 3-4 files to the server one by one,then whethere we can show the progress of each file sending to server in progress bar. so that the FTP clients can see the progress of file sending to the server.

any idea how we can do this to show the progress of each file sending. if we have 5 files to send, then the first file name and the progress of that files sending, after that second files progress as so on.

if you have any idea please let me know. if you can send examples that will be great helpful to me.

thanks in advance.
 
the attached program is the program i'm using to send files to server.

i'm not able to create a progress bar to show the progress of file sending to server in this program.

i checked ur links. and its good. but i dont have any idea how to use those inside this program.

if you have any idea please let me know. i'm new to programming that's why.
sorry for the disturbance.

thanks in advance.
 

Attachments

  • VB_FTP.zip
    22.7 KB · Views: 236
Use events

Hi,
You may declare events in clsFtp class and raise these events when the bytes are transfering.

for eg you may declare events like this,

VB.NET:
    Public Event FileUploading(ByVal pieceLength As Integer)
    Public Event FileUploadStarted(ByVal fileSize As Long)

and raise event inside the FileUpload function like this

VB.NET:
        If (File.Exists(sFileName)) Then

            ' Open input stream to read source file
            input = New FileStream(sFileName, FileMode.Open)

            RaiseEvent FileUploadStarted(input.Length)

            If (offset <> 0) Then
                input.Seek(offset, SeekOrigin.Begin)
            End If

            ' Upload the file 
            m_iBytes = input.Read(m_aBuffer, 0, m_aBuffer.Length)
            RaiseEvent FileUploading(m_iBytes)
            Do While (m_iBytes > 0)
                cSocket.Send(m_aBuffer, m_iBytes, 0)
                m_iBytes = input.Read(m_aBuffer, 0, m_aBuffer.Length)
                RaiseEvent FileUploading(m_iBytes)
            Loop
            input.Close()
        Else
            bFileNotFound = True
        End If

and in your application declare a variable as follows.

VB.NET:
    Private WithEvents ftp As New clsFTP("FtpIP", ".", "UserName", "Password", 21)

and indicate the progress as follows.
VB.NET:
    Private Sub ftp_FileUploading(ByVal pieceLength As Integer) Handles ftp.FileUploading
        Me.ProgressBar1.Value += pieceLength
    End Sub

    Private Sub ftp_FileUploadStarted(ByVal fileSize As Long) Handles ftp.FileUploadStarted
        Me.ProgressBar1.Maximum = fileSize
    End Sub
 
Back
Top