Smit Shah

.Net Download Entire FTP Directory

Below is a sniplet of code I used to download the entire FTP folder with sub folders and files.

You will need to download the DLL from

Simply copy paste the code below onto a console application, and you should be set to go.

Please note, you may have to do some error checking for your specific application.

The code below has not been tested and is a simple POC.

Imports System
Imports System.IO
Imports System.IO.File
Imports System.IO.FileInfo
Imports System.IO.Directory
Imports System.IO.DirectoryInfo
Imports System.Drawing

Module Module1

Private Sub DownloadEverything(ByVal FTPFolder As String, ByVal LocalFolder As String)
 Dim myFtp As New Utilities.FTP.FTPclient("hostname", "username", "password")
 Dim FTPDirectories = myFtp.ListDirectory(FTPFolder)
 For Each FTPDirectory In FTPDirectories
  With New DirectoryInfo(FTPDirectory)
   CreateDirectory(LocalFolder & "\" & .Name)
   DownloadEverything(FTPFolder & "/" & .Name, LocalFolder & "\" & .Name)
  End With
 Dim FTPFiles = myFtp.ListDirectoryDetail(FTPFolder).GetFiles
 For Each FTPFile In FTPFiles
  myFtp.Download(FTPFile, LocalFolder & "\" & FTPFile.Filename)
End Sub

Sub Main()
 Dim sLocalFolder As String = "C:\Temp\"
 Dim sRemoteFolder As String = "/"
 DownloadEverything(sRemoteFolder, sLocalFolder)
End Sub

End Module
This is a personal weblog. The opinions expressed here represent my own and not those of my employer. For accuracy and official reference refer to MSDN/ TechNet/ BOL /Other sites that are authorities in their field. Me or employer do not endorse any tools, applications, books, or concepts mentioned on the site. I have documented my personal experience on this site. The information on this site may not be up to date or accurate at times, if you are not sure or have a question, please contact me to verify information.