1

我有一小段 c# 测试代码 (4.7.2) 使用 FluentFtp 连接到基于 Linux 的未知类型和未知衍生 Linux 的服务器。

我正在 VS 2017 上开发。

我使用 NuGet 加载 FluentFTP。

我的测试代码的 .Net 级别是 4.7.2。

至今:

它连接。

我可以获得一个工作目录(GetWorkingDirectory())。

当我尝试获取文件列表时,它会显示“尝试连接超时!” 在 FluentFtp GetListing 上。

代码是:

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Text;
        using System.Threading.Tasks;
        using System.Net;
        using System.Security.Authentication;
        using System.Diagnostics;

        using FluentFTP;

        namespace TryFLuentFTP {
        class Program {
        static void Main(string[] args) {

            FtpTrace.AddListener(new ConsoleTraceListener());

            FtpTrace.LogUserName = false;   // hide FTP user names
            FtpTrace.LogPassword = false;   // hide FTP passwords
            FtpTrace.LogIP = false;     // hide FTP server IP addresses

            try {
                FtpClient client = new FtpClient("ftp-host", "user", "******"); 
                client.EncryptionMode = FtpEncryptionMode.Explicit;
                client.SslProtocols = SslProtocols.Tls12;

                client.DataConnectionType = FtpDataConnectionType.EPSV;                            //PASV;

                client.DownloadDataType = FtpDataType.Binary;

                client.ValidateCertificate += (c, e) => { e.Accept = true; };
                client.Connect();

                Console.WriteLine("Connected!!!!");

                Console.WriteLine("The working directory is: " + client.GetWorkingDirectory());

                FtpListItem[] list = client.GetListing(client.GetWorkingDirectory());
                // FtpListOption.Modify | FtpListOption.Size);

                foreach(FtpListItem li in list) {
                    Console.WriteLine(li.Type + " " + li.FullName);
                }

            } catch (Exception ex) {
                Console.WriteLine(ex.Message + "\n" + ex.StackTrace);
            }

            Console.ReadLine();
        }
    }
}

控制台输出是:

# Connect()
Status:   Connecting to ***:21
Response: 220 (vsFTPd 3.0.2)
Status:   Detected FTP server: VsFTPd
Command:  AUTH TLS
Response: 234 Proceed with negotiation.
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0.106716.
Command:  USER ***
Response: 331 Please specify the password.
Command:  PASS ***
Response: 230 Login successful.
Command:  PBSZ 0
Response: 200 PBSZ set to 0.
Command:  PROT P
Response: 200 PROT now Private.
Command:  FEAT
Response: 211 End
Response: 211-Features:
Response: AUTH TLS
Response: EPRT
Response: EPSV
Response: MDTM
Response: PASV
Response: PBSZ
Response: PROT
Response: REST STREAM
Response: SIZE
Response: TVFS
Response: UTF8
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 Always in UTF8 mode.
Command:  SYST
Response: 215 UNIX Type: L8
Status:   Auto-detected UNIX listing parser
Connected!!!!

# GetWorkingDirectory()
Command:  PWD
Response: 257 "/"
The working directory is: /

# GetWorkingDirectory()
Command:  PWD
Response: 257 "/"

# GetListing("/", Auto)
Command:  TYPE I
Response: 200 Switching to Binary mode.

# OpenPassiveDataStream(EPSV, "LIST /", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||30454|).
Status:   Connecting to ***:30454
Status:   Disposing FtpSocketStream...
Timed out trying to connect!
   at FluentFTP.FtpSocketStream.Connect(String host, Int32 port, FtpIpVersion ipVersions)
   at FluentFTP.FtpClient.Connect(FtpSocketStream stream, String host, Int32 port, FtpIpVersion ipVersions)
   at FluentFTP.FtpClient.OpenPassiveDataStream(FtpDataConnectionType type, String command, Int64 restart)
   at FluentFTP.FtpClient.OpenDataStream(String command, Int64 restart)
   at FluentFTP.FtpClient.GetListing(String path, FtpListOption options)
   at FluentFTP.FtpClient.GetListing(String path)
   at TryFLuentFTP.Program.Main(String[] args) in C:\DiabesityInstituteProjects\Solutions\DiabesityLabResultProcessing\TryFLuentFTP\Program.cs:line 38

我查看了许多 SO 帖子和 FluentFTP 问题,并尝试了几个想法。我也尝试过 PASV 和 EPSV,结果相同。

由于所有带有“tls”的 FTP 有点令人困惑,如果有替代品,直接 .Net 或第三方,我当然会招待他们。我有点时间紧张。

问候,吉姆

4

0 回答 0