Hi,

has anyone tried to download files from FTP using VB? I have tried using an FTP control for my project, my problem is I can't recursively search for files within subfolders, I tried using FSO but it doesn't work since the path from the server are something like this "/getdaat" unlike from the conventional one like "C:/"

thanks

Dani AI

Generated

For : FileSystemObject (FSO) operates on the local filesystem, so it won’t work against an FTP server path. Use an FTP API instead (System.Net.FtpWebRequest for classic .NET) or — better — a maintained FTP library/automation tool. Note that FtpWebRequest examples (ListDirectory/ListDirectoryDetails) target .NET Framework; FTP support changed in newer .NET, so using a maintained client library is generally safer. Microsoft: list directory with FTP. (learn.microsoft.com)

FtpWebRequest does not give you a portable “recursive list” call or a reliable machine-readable format on all servers, so the usual approach is: ListDirectoryDetails, parse each returned line to decide file vs. folder, then recurse into folders. That parsing is brittle (Unix LIST vs. IIS LIST formats), which is why MLSD/MLST were added to FTP as a machine-readable listing (RFC 3659) but aren’t universally available — you’ll need fallbacks. Example (VB.NET sketch — heuristics only):

Function ListFtp(path As String, creds As NetworkCredential) As List(Of String)
  Dim result As New List(Of String)
  Dim req = CType(WebRequest.Create("ftp://server" & path), FtpWebRequest)
  req.Method = WebRequestMethods.Ftp.ListDirectoryDetails
  req.Credentials = creds
  Using resp = CType(req.GetResponse(), FtpWebResponse)
    Using sr = New IO.StreamReader(resp.GetResponseStream())
      While Not sr.EndOfStream
        Dim line = sr.ReadLine()
        If IsDirectoryLine(line) Then
          Dim name = ExtractName(line)
          result.AddRange(ListFtp(path & "/" & name, creds))
        Else
          result.Add(path & "/" & ExtractName(line))
        End If
      End While
    End Using
  End Using
  Return result
End Function

This pattern is common but fragile; you’ll need to tune IsDirectoryLine/ExtractName for your server. (stackoverflow.com)

For a much easier, reliable solution use a library that handles MLSD/LIST parsing and recursion for you — for .NET, FluentFTP is widely used and exposes recursive listing/download helpers (and CHMOD where the server supports it). It will try MLSD first and fall back to parsers for common servers. FluentFTP directory listing docs. Example (VB.NET sketch):

Dim c = New FluentFTP.FtpClient("ftp.example.com") With {.Credentials = New NetworkCredential("u","p")}
c.Connect()
Dim all = c.GetListing("/start", FluentFTP.FtpListOption.Recursive)
For Each it In all
  If it.Type = FluentFTP.FtpFileSystemObjectType.File Then c.DownloadFile("C:\local\" & Path.GetFileName(it.FullName), it.FullName)
Next
c.Disconnect()

FluentFTP also exposes Chmod/permission helpers when the server supports SITE CHMOD. (github.com)

If you prefer a tested automation tool, WinSCP’s .NET assembly provides high-level methods (e.g., Session.GetFiles) for recursive transfers and good error-control examples. That’s handy if you want robust retries, logging or COM/.NET automation. WinSCP .NET examples for recursive downloads. (winscp.net)

Summary: avoid FSO; either implement careful LIST parsing + recursion (works, but brittle), or use FluentFTP / WinSCP .NET assembly for production-ready recursive listing/download and permission handling.

I'm using gFTP and it doesn't chmod recursively and it's a major pain in the back. So is there any Linux FTP client which can chmod recursively? It's not true that most of the ftp clients do it automatically, I don't know one which actually does, because 90% of the Linux ftp clients are frontends to 'ftp' and 'ftp' doesn't chmod recursively, at least not by default

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.