c# - 如何使用 FluentFTP 列出文件夹

标签 c# ftp fluentftp

我正在我的应用程序中实现 FluentFTP,但无法列出 FTP 服务器上文件夹的内容。
当我使用像 FileZilla 这样的 ftp 应用程序时,我可以清楚地看到我的用户目录中有 2 个文件夹:

enter image description here

Out 文件夹包含一些文件,但是当我使用 FluentFTP 检索列表时,我总是得到这 2 个文件夹,而不是 Out 文件夹的内容。

这是我正在使用的代码

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>
    }
}

我尝试了变量remoteDir的这些组合:

Out
/Out
Out/
/Out/

它们都不起作用,GetListing 总是重新调整 2 个文件夹,而不是 Out 文件夹的内容。

我做错了什么?

最佳答案

根据their docs

您应该能够使用

GetWorkingDirectory() - 获取当前工作目录的完整路径。

SetWorkingDirectory() - 设置当前工作目录的完整路径。

比如

FtpClient.SetWorkingDirectory("/Out");

关于c# - 如何使用 FluentFTP 列出文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41466095/

相关文章:

maven-2 - 使用 Maven 2 将程序集部署到 FTP 服务器

C# Entity Framework 查询存储过程错误 "Culture is not supported"

c# - 在本地时区格式化 UTC 时间戳

python - 在Python ftplib中在上传文件的名称中使用变量

ssl - dreamweaver如何连接google云上传页面

c# - 使用具有最大值的 FluentFTP 从 FTP 同时下载多个文件

c# - FluentFTP:根据验证程序,远程证书无效

c# - 使用 FluentFTP 下载文件

c# - 在c#代码中调用C++ dll

c# - 将 Kestrel 暴露于外界的风险