0 votes
by (8.6k points)
edited

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
by (18.1k points)
edited
 
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
ftp.ChangeDirectory("MyDir");

// 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));
}

ftp.Disconnect();
...