繁体   English   中英

尝试连接到sftp服务器时没有消息或超时

[英]No message or timeout when trying to connect to sftp server

我正在尝试连接到sftp服务器,我没有得到任何异常或超时,只是增加了内存使用量。

我正在使用EnterpriseDT.Net.Ftp库

我的代码是这样的:

XmlConfigurator.Configure();
      Module1.Logger = LogManager.GetLogger("SftpTester");
      try
      {
        Module1.Logger.Info((object) "[EnterpriseDT] - Start");
        Uri uri1 = new Uri("ftp://*****");
        // ISSUE: explicit reference operation
        // ISSUE: variable of a reference type
        Uri& uri2 = @uri1;
        int port = ****;
        string str1 = "******";
        // ISSUE: explicit reference operation
        // ISSUE: variable of a reference type
        string& UserName = @str1;
        string str2 = "*******";
        // ISSUE: explicit reference operation
        // ISSUE: variable of a reference type
        string& Password = @str2;
        SecureFTPConnection secureFtpConnection = Module1.InitConnection(uri2, port, UserName, Password);
        Module1.Logger.Info((object) "Connecting to ftp...");
        secureFtpConnection.Connect();
        Module1.Logger.Info((object) "Connection Successful!!!");
        try
        {
          Module1.Logger.Info((object) "Disposing connection...");
          secureFtpConnection.Dispose();
        }
        catch (Exception ex)
        {
          ProjectData.SetProjectError(ex);
          ProjectData.ClearProjectError();
        }
        Module1.Logger.Info((object) "Connection Disposed.");
      }
      catch (Exception ex)
      {
        ProjectData.SetProjectError(ex);
        Exception exception = ex;
        Module1.Logger.Error((object) ("Main() - " + exception.Message));
        Module1.Logger.Error((object) ("StackTrace: " + exception.StackTrace));
        if (exception.InnerException != null)
          Module1.Logger.Error((object) ("InnerException: " + exception.InnerException.Message));
        ProjectData.ClearProjectError();
      }
      finally
      {
        Module1.Logger.Info((object) "[EnterpriseDT] - End");
      }

  private static SecureFTPConnection InitConnection(ref Uri uri, int port, ref string UserName = "", ref string Password = "")
    {
      Module1.Logger.Info((object) "InitConnection() - Setting Up Connection");
      SecureFTPConnection secureFtpConnection = new SecureFTPConnection();
      secureFtpConnection.LicenseOwner = "*******";
      secureFtpConnection.LicenseKey = "***********";
      secureFtpConnection.ServerAddress = uri.Host;
      Module1.Logger.Info((object) ("\tHost: " + uri.Host));
      secureFtpConnection.UserName = UserName;
      Module1.Logger.Info((object) ("\tUsername: " + UserName));
      secureFtpConnection.Protocol = FileTransferProtocol.SFTP;
      Module1.Logger.Info((object) ("\tProtocol: " + FileTransferProtocol.SFTP.ToString()));
      secureFtpConnection.ServerValidation = SecureFTPServerValidationType.None;
      Module1.Logger.Info((object) ("\tServerValidation: " + SecureFTPServerValidationType.None.ToString()));
      secureFtpConnection.AuthenticationMethod = AuthenticationType.Password;
      Module1.Logger.Info((object) ("\tAuthenticationMethod: " + AuthenticationType.Password.ToString()));
      if (port > 0)
      {
        secureFtpConnection.ServerPort = port;
        Module1.Logger.Info((object) ("\tServerPort: " + port.ToString()));
      }
      secureFtpConnection.Password = Password;
      Module1.Logger.Info((object) ("\tPassword: " + Password));
      return secureFtpConnection;
    }

日志消息:

2014-09-27 04:50:22,783 [1] - [SftpTester] [EnterpriseDT] - Start
2014-09-27 04:50:22,799 [1] - [SftpTester] InitConnection() - Setting Up Connection
2014-09-27 04:50:22,971 [1] - [SftpTester] Host: *******
2014-09-27 04:50:22,971 [1] - [SftpTester] Username: *****
2014-09-27 04:50:22,971 [1] - [SftpTester] Protocol: SFTP
2014-09-27 04:50:22,971 [1] - [SftpTester] ServerValidation: None
2014-09-27 04:50:22,971 [1] - [SftpTester] AuthenticationMethod: Password
2014-09-27 04:50:22,971 [1] - [SftpTester] ServerPort: ****
2014-09-27 04:50:22,971 [1] - [SftpTester] Password: ******
2014-09-27 04:50:22,971 [1] - [SftpTester] Connecting to ftp...

不知道这是超时错误还是我在黑名单?

更新07/10/2014

服务器序列:

  1. 密码验证
  2. 等待包
  3. 包到了
  4. Auth部分成功。 尝试:密码,公钥,键盘交互
  5. 键盘交互认证
  6. 等待包
  7. 包到了
  8. 提示:密码:
  9. 等待包
  10. 包到了
  11. Auth部分成功。 尝试:密码,公钥,键盘交互
  12. 等待包
  13. 包到了
  14. 提示:密码:
  15. 循环(9到15)

更新

更新库解决问题,是一个错误。

版本8。6。1 (2014年9月23日)
修复了导致认证尝试循环的kbi重入错误。 修复了SFTP错误,其中将文件上载到不存在的目录时未引发异常。 修复了OpenVMS SFTP服务器未被识别为SSH的SFTP问题。 修复了重试下载问题,其中只进行了一次重新连接。 修复了使用FTPS在某些2012 R2计算机上“尝试读取或写入受保护内存”问题。

你的代码看起来不错。 没什么特别的。 您应该做的第一件事是在库中启用调试日志记录,因为您没有足够的有关FTP代码执行的信息。

您可以使用以下语句启用Debug:

EnterpriseDT.Util.Debug.Logger.CurrentLevel = EnterpriseDT.Util.Debug.Level.DEBUG;

默认情况下,它将在控制台中打印调试信息。 如果你愿意,你可以使用自定义appender(文件,数据库等)。 调试信息将为您提供有关该问题的更多信息。

是否有超时错误的任何想法?

我不这么认为。 默认情况下,库中的客户端超时设置为120000ms。 服务器超时可能要高得多。 我不认为这是一个超时问题。

我是黑名单?

也许,但不应该挂起FTP客户端。

为什么没有消息或超时呢?

挂起可能是由于FTP服务器或防火墙配置不正确造成的。 EnterpriseDT.Net.Ftp默认使用FTP Passive模式,就像大多数FTP客户端一样。 我建议检查您的FTP服务器和防火墙配置,并检查所有配置是否为Passive模式。

如果您的FTP服务器配置正确,您应该能够从任何FTP客户端连接到它。 您可以尝试FileZilla或任何其他客户端,只是为了确保您的服务器设置正确。 这样您就可以排除任何防火墙或FTP服务器问题。

更新:

从目前为止我们在日志中看到的是一个Auth问题。 看起来SSH服务器支持密码,公钥和键盘交互式身份验证。

我对您的日志的解释是您的SFTP客户端正在尝试按照以下确切的顺序使用以下方法进行身份验证:

Try: password, publickey, keyboard-interactive

密码验证(代码中的默认值)不通过(密码错误?)然后客户端切换到键盘验证,这就是您在SSH中获取密码提示的原因,并且SFTP库无法处理该情况,因为您没有包括快速响应。

为了解决这个问题,你应该在图书馆里检查出SSHAuthPrompt类,并包括在使用该代码的密码提示答案KBIPrompts对房地产SecureFTPConnection类:

http://www.enterprisedt.com/products/edtftpnetpro/doc/manual/api/html/T_EnterpriseDT_Net_Ftp_Ssh_SSHAuthPrompt.htm

这个类在构造函数中有两个参数。 提示应该与您从KBI获得的提示相匹配,并且应该是'Password:' ,响应值应该是密码。

您还应该尝试将AuthenticationMode配置为KeyboardInteractive。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM