c# – 尝试连接到sftp服务器时没有消息或超时
我正在尝试连接到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 服务器序列: >密码验证 更新 更新库解决问题,是一个错误. 版本8.6.1 解决方法
你的代码看起来不错.没什么特别的.您应该做的第一件事是在库中启用调试日志记录,因为您没有足够的有关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类,并使用SecureFTPConnection类上的KBIPrompts属性在代码中包含带密码的提示答案: http://www.enterprisedt.com/products/edtftpnetpro/doc/manual/api/html/T_EnterpriseDT_Net_Ftp_Ssh_SSHAuthPrompt.htm 这个类在构造函数中有两个参数.提示应该与您从KBI获得的提示相匹配,并且应该是“密码:”,响应值应该是密码. 您还应该尝试将AuthenticationMode配置为KeyboardInteractive. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |