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();