none
Download FTP Files with ProgressBar in Visual Basic RRS feed

  • Question

  • What  is the error here

    I got this error massage 

    An unhandled exception of type 'System.UriFormatException' occurred in System.dll
    
    Additional information: Invalid URI: The hostname could not be parsed.
    Code  ::


    Imports System.Net
        Public Class Form1
            Dim wc As New WebClient
            Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
                FolderBrowserDialog1.ShowDialog()
                Timer1.Start()
            End Sub
            Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
                path.Text$ = FolderBrowserDialog1.SelectedPath
                Timer1.Stop()
            End Sub
            Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
                Dim url As String = "ftp://" & user.Text$ & ":" & pw.Text$ & "@" & server.Text$ & file.Text$
                AddHandler wc.DownloadFileCompleted, AddressOf DownloadCompleted
                AddHandler wc.DownloadProgressChanged, AddressOf DownloadProgressChanged
            wc.DownloadFileAsync(New Uri(url), path.Text$ & "\" & file.Text.Substring(file.Text.LastIndexOf("/") + 1))
        End Sub
            Private Sub DownloadProgressChanged(ByVal sender As Object, ByVal e As Net.DownloadProgressChangedEventArgs)
                ProgressBar1.Value = e.ProgressPercentage
            End Sub
            Private Sub DownloadCompleted(ByVal sender As Object, ByVal e As System.ComponentModel.AsyncCompletedEventArgs)
                MsgBox("Successfully Downloaded!")
            End Sub
    
    End Class
    
    
    
    

    it seems like this line has an error

    wc.DownloadFileAsync(New Uri(url), path.Text$ & "\" & file.Text.Substring(file.Text.LastIndexOf("/") + 1))

    Wednesday, November 29, 2017 9:21 AM

All replies

  • Sam,

    The ultimate answer is going to be to put a breakpoint in, step into the code and see what URI is attempting to be created.

    The URI should be the server name, the delimeter, and the file's name. From something I set up a while back:

    Dim fileURI As New Uri(instructions.FTPS.ServerName & GetFileName(localFilePath))

    I'm sure that doesn't make sense because you're seeing it out of context but it's the servername & "/"c & filename.


    "A problem well stated is a problem half solved.” - Charles F. Kettering


    • Edited by Frank L. Smith Wednesday, November 29, 2017 10:36 AM ...typo
    Wednesday, November 29, 2017 10:30 AM
  • Hi Sam.sam.net,

    From your code, there is no problem, so I guess there may be a problem in the place you typed. For example, user.Text enter username, pw.Text enter password, server.Text enter server, file.Text enter the  /filename, this is where attention needs to be done.

    If still have error, please add breakpoint to show URL to see if having some error.

    Best Regards,

    Cherry


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Thursday, November 30, 2017 3:10 AM
    Moderator
  • Sam,

    How are you making out with it? Did you get the problem worked out?

    If not, you might want to have a look at this thread from a few months ago:

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/d7fd086b-6e09-4bf5-9794-ec7d99e5df23/error-on-systemargumentoutofrangeexception?forum=vbgeneral

    Ignore the OP's question; he was mistaken about what was going on. Instead, scroll down about halfway to get the reply which was marked as the answer.

    I think that might give you some insight?

    Let us know please.


    "A problem well stated is a problem half solved.” - Charles F. Kettering

    Thursday, November 30, 2017 11:01 PM