FluentFtp Azure ftp 用户在几次成功连接后无法登录

问题描述

我在多次尝试访问 ftp 时遇到了一些问题。例如,我们在 ftp 中有一百个文件,我尝试在每个请求/端点命中时下载一个。在随机连接数之后,日志显示有一段时间我们无法再登录到 ftp,但在进一步的过程中它会自行更正。这会不会是短时间内请求过多造成的?非常感谢提高连接可靠性的任何想法?

2021-02-24 14:56:02.601 +00:00 [information] Status:   Connecting to xx.xx.xx.xx:21
2021-02-24 14:56:02.613 +00:00 [information] Response: 220 Microsoft FTP Service
2021-02-24 14:56:02.614 +00:00 [information] Status:   Detected FTP server: WindowsServerIIS
2021-02-24 14:56:02.617 +00:00 [information] Command:  AUTH TLS
2021-02-24 14:56:02.624 +00:00 [information] Response: 234 AUTH command ok. Expecting TLS Negotiation.
2021-02-24 14:56:02.629 +00:00 [information] Status:   FTPS Authentication Successful
2021-02-24 14:56:02.630 +00:00 [information] Command:  USER xxx\$xxxftp
2021-02-24 14:56:02.634 +00:00 [information] Response: 331 Password required
2021-02-24 14:56:02.635 +00:00 [information] Command:  PASS ***
2021-02-24 14:56:02.696 +00:00 [information] Response: 230 User logged in.
2021-02-24 14:56:02.697 +00:00 [information] Command:  PBSZ 0
2021-02-24 14:56:02.702 +00:00 [information] Response: 200 PBSZ command successful.
2021-02-24 14:56:02.703 +00:00 [information] Command:  PROT P
2021-02-24 14:56:02.707 +00:00 [information] Response: 200 PROT command successful.
2021-02-24 14:56:02.708 +00:00 [information] Command:  FEAT
2021-02-24 14:56:02.711 +00:00 [information] Response: 211 END
2021-02-24 14:56:02.712 +00:00 [information] Status:   Text encoding: System.Text.UTF8Encoding+UTF8EncodingSealed
2021-02-24 14:56:02.713 +00:00 [information] Command:  OPTS UTF8 ON
2021-02-24 14:56:02.716 +00:00 [information] Response: 200 OPTS UTF8 command successful - UTF8 encoding Now ON.
2021-02-24 14:56:02.716 +00:00 [information] Command:  SYST
2021-02-24 14:56:02.719 +00:00 [information] Response: 215 Windows_NT
2021-02-24 14:56:02.720 +00:00 [information] Command:  TYPE I
2021-02-24 14:56:02.723 +00:00 [information] Response: 200 Type set to I.
2021-02-24 14:56:02.724 +00:00 [information] Command:  PASV
2021-02-24 14:56:02.727 +00:00 [information] Response: 227 Entering Passive Mode (52,166,149,40,6).
2021-02-24 14:56:02.728 +00:00 [information] Status:   Connecting to xx.xx.xx.xx:10246
2021-02-24 14:56:02.731 +00:00 [information] Command:  RETR /site/ftp/xxx.pdf
2021-02-24 14:56:02.736 +00:00 [information] Response: 125 Data connection already open; Transfer starting.
2021-02-24 14:56:02.741 +00:00 [information] Status:   FTPS Authentication Successful
2021-02-24 14:56:02.835 +00:00 [information] Response: 226 Transfer complete.
2021-02-24 14:56:02.836 +00:00 [information] Command:  QUIT
2021-02-24 14:56:02.842 +00:00 [information] Response: 221 Goodbye.
2021-02-24 14:56:02.854 +00:00 [information] Status:   Connecting to 52.166.149.149:21
2021-02-24 14:56:02.861 +00:00 [information] Response: 220 Microsoft FTP Service
2021-02-24 14:56:02.861 +00:00 [information] Status:   Detected FTP server: WindowsServerIIS
2021-02-24 14:56:02.862 +00:00 [information] Command:  AUTH TLS
2021-02-24 14:56:02.865 +00:00 [information] Response: 234 AUTH command ok. Expecting TLS Negotiation.
2021-02-24 14:56:02.870 +00:00 [information] Status:   FTPS Authentication Successful
2021-02-24 14:56:02.872 +00:00 [information] Command:  USER xxxftp\$xxxftp
2021-02-24 14:56:02.874 +00:00 [information] Response: 331 Password required
2021-02-24 14:56:02.875 +00:00 [information] Command:  PASS ***
2021-02-24 14:56:02.884 +00:00 [information] Response: 530 User cannot log in.
2021-02-24 14:56:02.884 +00:00 [information] Command:  QUIT
2021-02-24 14:56:02.887 +00:00 [information] Response: 221 Goodbye.

和负责连接的代码

 private void InitializeftpConnection(FtpClient _ftpClient)
    {
        if (!_ftpClient.IsConnected)
        {
            _ftpClient.EncryptionMode = FtpEncryptionMode.Explicit;
            _ftpClient.SslProtocols = SslProtocols.Tls12;
            _ftpClient.DataConnectionType = FtpDataConnectionType.PASV;
            _ftpClient.RetryAttempts = 10;
            _ftpClient.OnLogEvent = OnFTPLogEvent;
            _ftpClient.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);

            _ftpClient.Connect();              
        }
    }

    //method called from service
    private byte[] TryGetFile(string filename,FileStorageLocation fromLocation)
    {
        byte[] fileDownload = null;

        for (int i = 1; i <= retryCount; i++)
        {
            using (var _ftpClient = new FtpClient(_activeAddress,_username,_password))
            {
                try
                {
                    InitializeftpConnection(_ftpClient);
                    _ftpClient.Download(out fileDownload,$"{GetBaseUrl(fromLocation)}/{filename}");
                    return fileDownload;
                }
                catch (Exception e)
                {
                    if (i == retryCount)
                    {
                        throw new Exception("Failed downloading a file from the FTP server.",e);
                    }
                }
            }
        }
        return null;
    }

更新: 就像作为 FTP 的 azure 应用服务一样。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)