How to download a whole FTP directory without using Download method

0 votes
asked May 29, 2013 by Rebex KB (8,430 points)
edited May 29, 2013

I'm trying to download all files from an FTP directory using the Download method. However, I'm getting the following error: "It is not easily possible to determine whether a file or directory exists at this server. Batch operations will not work."

Applies to: Rebex FTP/SSL

1 Answer

0 votes
answered May 29, 2013 by Jan Sotola (17,670 points)
edited May 29, 2013
Best answer

Some FTP servers (usually some mainframe systems etc.) do not allow to check, whether a specified path is a file or a directory or whether it exists at all. On such servers, multiple file transfer operations (like Upload or Download methods) cannot work. You have to use PutFile, GetFile and GetList methods only.

Here is an example for non-recursive download of all files of a directory without using the powerful Download method:

// connect and login to the FTP server
var ftp = new Ftp();
ftp.Connect("testftp.local", 1021, SslMode.Explicit);
ftp.Login("tester", "test");

// change to desired directory

// get list of all items of the directory (both files and subdirectories)
var lst = ftp.GetList();

// download all files from this directory
foreach (var item in lst)
    // from a list item, we can always distinguish file and directory
    if (item.IsFile)
        ftp.GetFile(item.Name, System.IO.Path.Combine(@"c:\temp", item.Name));