加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-15 22:08:34 所属栏目:百科 来源:网络整理
导读:我正在尝试连接到sftp服务器,我没有得到任何异常或超时,只是增加了内存使用量. 我正在使用EnterpriseDT.Net.Ftp库 我的代码是这样的: XmlConfigurator.Configure(); Module1.Logger = LogManager.GetLogger("SftpTester"); try { Module1.Logger.Info((obje
我正在尝试连接到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

服务器序列:

>密码验证
>等待包
>包到了
> Auth部分成功.尝试:密码,公钥,键盘交互
>键盘交互式身份验证
>等待包
>包到了
>提示:密码:
>等待包
>包到了
> Auth部分成功.尝试:密码,键盘交互
>等待包
>包到了
>提示:密码:
>循环(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(文件,数据库等).调试信息将为您提供有关该问题的更多信息.

Any idea about if is a timeout error?

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

Am in a blacklist?

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

Why there is No message or timeout then?

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

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

更新:

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

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

Try: password,publickey,keyboard-interactive

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

要解决此问题,您应该检查库中的SSHAuthPrompt类,并使用SecureFTPConnection类上的KBIPrompts属性在代码中包含带密码的提示答案:

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

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

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读