I'm trying to connect to a sftp server and I don't get any exception or timeout, only increasing memory usage.
I am using the library EnterpriseDT.Net.Ftp
My code is like this:
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;
}
Log message:
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...
Any idea if this is a timeout error or if I am in a blacklist?
Update 07/10/2014
Sequence for server:
update
Updating the library solve the problem, was a bug.
Version 8.6.1 (23 Sep 2014)
Fixed kbi re-entrant bug that causes a loop of authentication attempts. Fixed SFTP bug where an exception wasn't thrown when uploading a file to a non-existent directory. Fixed SFTP problem where an OpenVMS SFTP server wasn't being recognized as SSH. Fixed retry download problem where only one reconnect was made. Fixed "Attempted to read or write protected memory" issue on some 2012 R2 machines using FTPS.
Your code looks ok. There is nothing special about it. The first thing you should do is enable Debug logging in the library, since you don't have enough information about the execution of your FTP code.
You can enable Debug with the following statement:
EnterpriseDT.Util.Debug.Logger.CurrentLevel = EnterpriseDT.Util.Debug.Level.DEBUG;
By default it will print debug info in the Console. you can use a custom appender (file, db etc.) if you like. The Debug info will give you much more information about the issue.
Any idea about if is a timeout error?
I don't think so. There is a client timeout set to 120000ms in the library by default. The Server timeouts are probably much higher. I don't think it is a timeout issue.
Am in a blacklist?
Maybe, but again that shouldn't hang an FTP client.
Why there is No message or timeout then?
Hangs could be caused by improper FTP Server or Firewall config. EnterpriseDT.Net.Ftp uses FTP Passive mode by default like most FTP clients. I would suggest checking your FTP server and firewall configuration and check everything is configured properly for Passive mode.
If your FTP Server is configured properly, you should be able to connect to it from any FTP client. You can try FileZilla or any other client, just to make sure your server is setup correctly. That way you will rule out any firewall or FTP server issues.
Update:
From what we see so far in the log it is an Auth issue. Looks like the SSH server supports password, publickey and keyboard-interactive auth.
My interpretation of your log above is that your SFTP client is trying to authenticate with the following methods in this exact order:
Try: password, publickey, keyboard-interactive
Password authentication (the default in your code) doesn't go through (wrong password?) and then the client switches to Keyboard authentication and that's why you are getting a password prompt in SSH, and the SFTP library is not able to handle that scenario, since you are not including a prompt response.
To fix that you should check out the SSHAuthPrompt class in the library, and include the prompt answer with the password in your code using the KBIPrompts
property on the SecureFTPConnection
class:
This class has two params in the constructor. The prompt should match what you are getting from KBI, and that should be 'Password:'
, the response value should be the password.
You should also try configuring the AuthenticationMode to KeyboardInteractive.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.