How to list a folder using FluentFTP

GuidoG picture GuidoG · Jan 4, 2017 · Viewed 11.8k times · Source

I am implementing FluentFTP in my application but I cannot list the contents of a folder on the FTP server.
When I use an ftp application like FileZilla I can clearly see that in my user directory there are 2 folders :

enter image description here

The Out folder contains some files, but when I retrieve a listing using FluentFTP I always get these 2 folders, not the contents of the Out folder.

This is the code I am using

FtpClient client = new FtpClient();
client.Host = _ftpDefinition.Host;
client.Port = _ftpDefinition.Port;
client.Credentials = new NetworkCredential(_ftpDefinition.UserName, _ftpDefinition.PassWord);
client.Connect();

foreach (FtpListItem item in ftpClient.GetListing(remoteDir))
{
    if (item.Type == FtpFileSystemObjectType.File)
    {
         _remoteFiles.Add(item.Name); // add the filename to a List<string>
    }
}

I tried these combinations for the variable remoteDir :

Out
/Out
Out/
/Out/

none of them is working, the GetListing always retuns the 2 folders in stead of the contents of the Out folder.

What am I doing wrong ?

Answer

BugFinder picture BugFinder · Jan 4, 2017

According to their docs

You should be able to use

GetWorkingDirectory() - Gets the full path of the current working directory.

SetWorkingDirectory() - Sets the full path of the current working directory.

Such as

FtpClient.SetWorkingDirectory("/Out");