Note: Forums will be making significant UX changes to address key usability improvements surrounding search, discoverability and navigation. To learn more about these changes please visit the announcement which can be found HERE.

Locked Upload file using FTP with Progress Bar

  • Tuesday, February 26, 2008 10:37 PM
     
     

    Hello

    I use this method (My.Computer.Network.UploadFile) to upload files by FTP.

    But I want to upload file with using ProgressBar control not using its progress bar.

    How can I do that?

     

    Thanks

All Replies

  • Friday, February 29, 2008 5:47 AM
     
     

    Penicillin,

     

    This thread File Upload with a progressbar can help you very well on your project with the answer by Daniel Kuppitz:

     

    Code Snippet

        Sub UpdateProgressBar(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)

            If progressBar1.InvokeRequired Then

                progressBar1.Invoke( _

                New UploadProgressChangedEventHandler(AddressOf UpdateProgressBar), _

                sender, e)

                Exit Sub

            End If

            progressBar1.Value = CInt(progressBar1.Minimum + _

            ((progressBar1.Maximum - progressBar1.Minimum) * _

              e.ProgressPercentage) / 100)

        End Sub

     

        Private Sub btnUpload_Click( _

        ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click

     

            Dim client As New System.Net.WebClient()

            AddHandler client.UploadProgressChanged, AddressOf UpdateProgressBar

            With client

                .Credentials = New NetworkCredential( _

                "MyFTPUsername", "MyFTPPassword")

                .UploadFile("ftp://webserverurl.com/public_html/test.zip", _

                "C:\Users\Dreadypeetje\Downloads\test.zip")

            End With

        End Sub

     

        Sub UploadFile()

            Dim client As New System.Net.WebClient()

            AddHandler client.UploadProgressChanged, AddressOf UpdateProgressBar

            With client

                .Credentials = New NetworkCredential( _

                "MyFTPUsername", "MyFTPPassword")

                .UploadFile("ftp://webserverurl.com/public_html/test.zip", _

                "C:\Users\Dreadypeetje\Downloads\test.zip")

            End With

        End Sub

     

     

     

  • Saturday, March 01, 2008 2:03 AM
     
     Answered

    Hello

    Look at my code:

    It doesn't upload at all:

    Code Snippet

    Imports System.Net

     

    Public Class Form1

     

    Sub UpdateProgressBar(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)

    If ProgressBar1.InvokeRequired Then

    ProgressBar1.Invoke(New UploadProgressChangedEventHandler(AddressOf UpdateProgressBar), sender, e)

    Exit Sub

    End If

    ProgressBar1.Value = CInt(ProgressBar1.Minimum + ((ProgressBar1.Maximum - ProgressBar1.Minimum) * e.ProgressPercentage) / 100)

    End Sub

     

    Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    BackgroundWorker1.RunWorkerAsync()

    End Sub

     

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    Dim client As New System.Net.WebClient()

    AddHandler client.UploadProgressChanged, AddressOf UpdateProgressBar

    With client

    .Credentials = New NetworkCredential("username", "password")

    .UploadFileAsync(New Uri("ftp://ftp.server.com/www/test.zip"), "D:\test.zip")

    End With

    End Sub

     

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted

    MsgBox("Done")

    End Sub

    End Class

     

     

    What's wrong?

    Thanks

  • Monday, March 03, 2008 7:41 AM
     
     Answered

    Penicillin,

     

    Thanks for the reply. How is your problem going?

     

    Since the method cannot help you to upload the files with ProgressBar control, could you please provide the specific information on the error message or exceptions of using this UpdateProcessBar method?

     

    You can also take a look at the System.Net.WebClient.UploadFileAsync that iploads the specified local file to the specified resource using POST method and the related overloads methods with the different parameters.

     

    In addition, please make sure the Uri instance is correct. The System.Uri Class in MSDN shows you the correct way to use. The article How to: Upload Files with FTP and Simple FTP Upload in C# w Free FTP DLL provides you with more examples.

     

    Hope that can help you.

  • Monday, March 03, 2008 12:35 PM
     
     

    I used this code:

    Code Snippet

    Imports System.Net

    Public Class Form1

     

    Sub UpdateProgressBar(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)

    If ProgressBar1.InvokeRequired Then

    ProgressBar1.Invoke(New UploadProgressChangedEventHandler(AddressOf UpdateProgressBar), sender, e)

    Exit Sub

    End If

    ProgressBar1.Value = CInt(ProgressBar1.Minimum + ((ProgressBar1.Maximum - ProgressBar1.Minimum) * e.ProgressPercentage) / 100)

    End Sub

     

    Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    BackgroundWorker1.RunWorkerAsync()

    End Sub

     

    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    Dim client As New System.Net.WebClient()

    AddHandler client.UploadProgressChanged, AddressOf UpdateProgressBar

    With client

    .Credentials = New NetworkCredential("username", "pass")

    .UploadFileAsync(New Uri("ftp://ftp.server.com/www/file.zip"), "D:\file.zip")

    End With

    End Sub

     

    Private Sub BackgroundWorker1_RunWorkerCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted

    MsgBox("Done")

    End Sub

    End Class

     

     

    After pressing button, I got message "Done", but the file wasn't uploaded, so the progressbar isn't moving.

    What's wrong?

     

    Thanks

  • Tuesday, March 04, 2008 2:50 AM
     
     

    Penicillin,

     

    1. Please make sure you have the access to upload files on to ftp.server.com/www with the correct login account.

     

    2. Please try to upload the file manually without the program, in order to make clear what cause the problem.

     

    3. It seems that the project runs well on your machine, however, the result is unexpected. In this case, it is difficult to find out the mistake from Visual Studio debug mode. You can try to use other tools such as FileMon, WinDbg to check the procedure of your source code execution.

     

    If there is any further question, please feel free to reply.

  • Wednesday, March 05, 2008 5:04 PM
     
     
     Bruno Yu - MSFT wrote:

    Penicillin,

     

    1. Please make sure you have the access to upload files on to ftp.server.com/www with the correct login account.

     

    2. Please try to upload the file manually without the program, in order to make clear what cause the problem.

     

    3. It seems that the project runs well on your machine, however, the result is unexpected. In this case, it is difficult to find out the mistake from Visual Studio debug mode. You can try to use other tools such as FileMon, WinDbg to check the procedure of your source code execution.

     

    If there is any further question, please feel free to reply.

    1- Yes, I'm sure that ftp.server.com/www is correct address, username and password are too.

    2- I did and I could successfully.

    3- I have Vista so I can't run FileMon, but I didn't know what to download in WinDbg site.
  • Thursday, March 06, 2008 6:57 AM
     
     

    Penicillin

     

    You can download the WinDbg tool in the link below:

     

    http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx 

     

    The article from Code Project can help you with this issue:

     

    Windows Debuggers: Part 1: A WinDbg Tutorial

    http://www.codeproject.com/debug/windbg_part1.asp

     

     

  • Friday, March 14, 2008 11:47 PM
     
     
     Bruno Yu - MSFT wrote:

    Penicillin

     

    You can download the WinDbg tool in the link below:

     

    http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx 

     

    The article from Code Project can help you with this issue:

     

    Windows Debuggers: Part 1: A WinDbg Tutorial

    http://www.codeproject.com/debug/windbg_part1.asp

     

     

    Hi

    I installed WinDbg.

    But I didn't know how to work, and what it's gonna help me to fix my project?

  • Monday, March 17, 2008 8:40 AM
     
     

    Penicillin,

     

    WindDbg is the debug tool just like the Visual Studio Debugger used in your development. Since the file cannot uploaded, you can use WinDbg to watch the detailed information on the execution of your project, or set some break points during the debug procedure, in order to make clear why the related method cannot upload the file and what happens when the related upload method executes in CLR and even in operating system level.

     

    There are many commands in using WinDbg tool, in my opinion, the best instruction is the Debugging Help document after you install the tool.

  • Sunday, August 26, 2012 7:20 AM
     
     Proposed Has Code

    I tried the code, and it did work in the sense that the file uploaded to the ftp server correctly. However, the progress bar did not update at all. Can someone help me fix the problem?

    Imports System.Net
    
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
        End Sub
    
        Sub UpdateProgressBar(ByVal sender As Object, ByVal e As UploadProgressChangedEventArgs)
            If ProgressBar1.InvokeRequired Then
                ProgressBar1.Invoke(New UploadProgressChangedEventHandler(AddressOf UpdateProgressBar), sender, e)
                Exit Sub
            End If
            ProgressBar1.Value = CInt(ProgressBar1.Minimum + _
            ((ProgressBar1.Maximum - ProgressBar1.Minimum) * _
              e.ProgressPercentage) / 100)
        End Sub
    
        Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
            Label1.Text = "Uploading now..."
            Label1.Update()
    
            Dim client As New System.Net.WebClient()
            AddHandler client.UploadProgressChanged, AddressOf UpdateProgressBar
            With client
                .Credentials = New NetworkCredential( _
                "ftpuser@ftpserver.tld", "mypassword")
                .UploadFile("ftp://myserver.in/header.jpg", "C:\Users\MyUsername\Desktop\header.jpg")
            End With
            Label1.Text = "Done!"
            Label1.Update()
    
        End Sub
    
        Sub UploadFile()
            Dim client As New System.Net.WebClient()
            AddHandler client.UploadProgressChanged, AddressOf UpdateProgressBar
            With client
                .Credentials = New NetworkCredential( _
                "ftpuser@ftpserver.tld", "mypassword")
                .UploadFile("ftp://myserver.in/header.jpg", _
                "C:\Users\MyUsername\Desktop\header.jpg")
            End With
        End Sub
    
        Private Sub ProgressBar1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgressBar1.Click
    
        End Sub
    End Class
    

    P.S: I know the thread is 4 years old. But nothing else that I found matches this problem closely.

    • Proposed As Answer by AllanChafin Tuesday, September 04, 2012 1:53 AM
    •  
  • Tuesday, September 04, 2012 1:54 AM
     
     
    Were you able to find a resolve to this?