空 FTP 目录中的两个条目

Two entries in empty FTP directory

我正在尝试创建一个列表,列出在 FTP 服务器上的文件夹中找到的所有文件名。完整目录与登录凭据一起保存在设置数据库 table 中。它可以很好地连接到 FTP 区域,我可以从它进出 upload/download 文件。

这是我从文件夹中获取文件的代码。

lstFiles = new List<string>();

string remoteFTPPath = ftpLocation;
var request = (FtpWebRequest)WebRequest.Create(remoteFTPPath);

request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential(ftpUsername, ftpPassword);
request.Proxy = null;

FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);

List<string> directories = new List<string>();

string line = reader.ReadLine();

while (!string.IsNullOrEmpty(line))
{
   directories.Add(line);
   line = reader.ReadLine();
}
reader.Close();

我遇到的问题是目前我尝试搜索的文件夹是空的,但它找到了 2 个文件。

这是为什么?

remoteFTPPath中的值为ftp://ftp.myArea.co.uk/myServer.co.uk/System-Files/

这是我在 FileZilla 中打开它时的文件夹 - 它绝对是一个空文件夹。

如何查看系统文件中的所有文件并将它们放入列表中?

FileZilla 日志:

Status: Logged in
Status: Retrieving directory listing of "/myArea.co.uk"...
Status: Directory listing of "/myArea.co.uk" successful
Status: Retrieving directory listing of "/myArea.co.uk/System-Files"...
Status: Directory listing of "/myArea.co.uk/System-Files" successful

并且在 C# 应用程序上测试相同代码时,Network.log 文件输出如下。

System.Net Information: 0 : [6132] FtpWebRequest#60068066::.ctor(ftp://ftp.myServer.co.uk/myArea.co.uk/System-Files/)
System.Net Information: 0 : [6132] Current OS installation type is 'Client'.
System.Net Information: 0 : [6132] FtpWebRequest#60068066::GetResponse(Method=LIST.)
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Created connection from xxx.xxx.x.xx:YYYY to xxx.xxx.xxx.x:YY.
System.Net Information: 0 : [6132] Associating FtpWebRequest#60068066 with FtpControlStream#34640832
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [220-Matrix FTP server ready.
220-This is a private system - No anonymous login
220-IPv6 connections are also welcome on this server.
220 Please note: files for your website must be stored under the htdocs directory.]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [USER myUser]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [331 User myUser OK. Password required]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [PASS ********]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [230 OK. Current directory is /]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [OPTS utf8 on]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [500 Unknown command]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [PWD]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [257 "/" is your current location]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [CWD /myArea.co.uk/System-Files]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [250 OK. Current directory is /myArea.co.uk/System-Files]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [TYPE I]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [200 TYPE is now 8-bit binary]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [PASV]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [227 Entering Passive Mode (213,171,193,5,117,157)]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Sending command [LIST]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [150 Accepted data connection]
System.Net Information: 0 : [6132] FtpControlStream#34640832 - Received response [226-ASCII
226-Options: -a -l
226 2 matches total]
System.Net Information: 0 : [6132] FtpWebRequest#60068066::(Releasing FTP connection#34640832.)
System.Net Information: 0 : [14644] ServicePoint#33675143 - Closed as idle.

许多 FTP 服务器 return ... 目录列表中的条目,类似于 *nix ls -a 或 Windows dir 命令。这些分别是对目录本身和父目录的引用。

任何目录,甚至是空目录(有时 [例如 Windows 服务器上],根文件夹除外),您都会得到它们。

如果您不想要这些,您需要在代码中过滤掉它们。 FileZilla 也确实做了什么。