Results 1 to 9 of 9

Thread: FTP Download to specified Directory Error

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    FTP Download to specified Directory Error

    HI,

    Desktop app VS 2022 VB.net VB


    I'm trying to FTP a file to "My Documents/PDFs" folder with a desktop app. I have the FTP working just fine but when I set/change the destination path to "My Documents" , "Documents" or "Downloads" (preferred) I get and error
    " InnerException: {"Could not find a part of the path 'C:\Downloads\61503.pdf'."}"
    I know the C:\downloads directory exists.
    Any Ideas?
    Code:
      Dim FilenameIs As String = ("61503.pdf")
      Dim destinationPath As String = ("C:/Downloads\61503.pdf")
      Dim client As New WebClient()
      client.Credentials = New NetworkCredential("SigPics", "MtPWD") ' Replace with actual credentials
    
      Try
          'client.DownloadFile("ftp://ftp.dashleywebs.com/61503.jpg", "C:\Users\Public\Pictures\" & FilenameIs & "") ' Replace with actual paths
          client.DownloadFile("ftp://ftp.dashleywebs.com/61503.jpg", destinationPath) ' Replace with actual paths
          Console.WriteLine("File downloaded successfully using WebClient.")
      Catch ex As Exception
          Console.WriteLine("Error downloading file: " & ex.Message)
      End Try

  2. #2
    PowerPoster jdc2000's Avatar
    Join Date
    Oct 2001
    Location
    Idaho Falls, Idaho USA
    Posts
    2,525

    Re: FTP Download to specified Directory Error

    Code:
    C:/Downloads\61503.pdf
    Should be:
    Code:
    C:\Downloads\61503.pdf

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    Re: FTP Download to specified Directory Error

    @jdc2000


    I had it that way and and tried both slashes. Either way with C:\Downloads\61503.pdf I still get

    InnerException: {"Could not find a part of the path 'C:\Downloads\61503.pdf'."}

    If I change the destination to Dim destinationPath As String = ("C:\Users\Public\Pictures\61503.jpg")
    It downloads to that folder. Just can't get it into Downloads folder
    Last edited by dashley; Oct 7th, 2025 at 11:12 AM.

  4. #4
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: FTP Download to specified Directory Error

    What version of .NET are you using? Also, what is the Exception (not just the InnerException)?

    The reason I ask is because in .NET core, Microsoft's official position is (reference):
    Recommended action
    Use the System.Net.Http.HttpClient class instead.

    For FTP, since HttpClient doesn't support it, we recommend using a third-party library.
    And for the Exception, it very well could be a permissions issue. You can double-check this by running your application as an administrator.
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  5. #5
    Fanatic Member
    Join Date
    Jun 2019
    Posts
    579

    Re: FTP Download to specified Directory Error

    For FTP just try FluentFTP NuGet package. It is open source, MIT license.

    Source code link: https://github.com/robinrodricks/FluentFTP

    Check this sample (from the repository in GitHub):
    https://github.com/robinrodricks/Flu...ownloadFile.vb

  6. #6
    PowerPoster Arnoutdv's Avatar
    Join Date
    Oct 2013
    Posts
    6,734

    Re: FTP Download to specified Directory Error

    Does C:\Downloads exists??
    If you refer to the Download folder this is located in your user folder.
    Something like this:
    C:\Users\Arnoutdv\Downloads

  7. #7

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    Re: FTP Download to specified Directory Error

    The cure was
    Dim userprof As String = Environ("USERPROFILE")
    Dim destinationPath As String = (userprof & "\downlaods\61503.jpg")

    It had to go to c:\users\<username>\downloads\myfilename
    or in m y case c:\users\dan\downloads\filename

    Thanks Arnoutdv

    -dan

  8. #8
    Super Moderator dday9's Avatar
    Join Date
    Mar 2011
    Posts
    12,371

    Re: FTP Download to specified Directory Error

    Ah, I incorrectly assumed that you did indeed want to go to C:\downloads and not the user profile's downloads. In that case, use this instead, it is a much better solution:
    Code:
    Private Function GetDestinationPath(filename As String) As String
        Dim userProfilePath As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
        Dim destinationPath As String = IO.Path.Combine(userProfilePath, "Downloads", filename)
        Return destinationPath
    End Function
    
    ' usage: Dim destinationPath As String = GetDestinationPath("61503.jpg")
    "Code is like humor. When you have to explain it, it is bad." - Cory House
    VbLessons | HtmlLessons | CssLessons | Code Tags | Sword of Fury - Jameram

  9. #9

    Thread Starter
    Member
    Join Date
    Aug 2011
    Posts
    42

    Re: FTP Download to specified Directory Error

    @dday C:\downloads was my intent but the user profile' downloads works just as well. I Like the function you provided to so I shall use it. Since this app wil run on multiple desktops the use profile is still good.
    to answer your ealier question(s) The framework is 4.7.2 and the actual error was: Message: "An exception occurred during a WebClient request." Status: UnknownError {16}.
    I agree I think it was a permissons issue. Dosen't matter now. It's working with the user profile downloads so I'm content.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width