FluentFtp使用tls连接到FTP服务器,可以获取工作目录,但是尝试获取文件列表超时

时间:2019-07-03 02:31:31

标签: c# connect fluentftp

我有使用FluentFtp的一小段c#测试代码(4.7.2),该代码连接到基于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或第三方,我当然会乐在其中。我的时间有点紧。

关于, 吉姆

0 个答案:

没有答案