When the application tries to connect, it gets stuck at sftp.connect. The application will not error out or anything. I’m thinking that it may be the prompt to save the server key. Any way to save that key or to go around this issue?
Hi,
int port = 22; // the default port
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
authenticationInfo.UserName = “ftpuser”;
authenticationInfo.Password = “pwd”;
if (publicKey == true)
{
Console.Write("\nEnter path to file containing publickey: ");
string path = “ssh.key”;
if (File.Exists(path))
authenticationInfo.LoadPrivateKey(path);
else
{
Console.WriteLine(“The specified file doesn’t exist. Publickey authentication will be disabled”);
}
}
// connecting to the server
SftpClient client = new SftpClient();
try
{
client.Connect(host, port, authenticationInfo);
Console.WriteLine(“Successfully connected”);
}
catch (Exception exception)
{
Console.WriteLine(exception.Message);
}
The problem is that I don’t have the “.key” file. No point in doing the prompt if you don’t have it in the first place.
What happens is, when you connect to the server using a 3rd party FTP tool like Core FTP with SFTP capability, I get a prompt if I want to save the server key into the application (this is Core FTP) which saves it onto itself. I now have the key but the problem is how do you make it into a “.key” file?
Hi,
If your SFTP server does not require key authentication, then no key file is required. Only the correct credentials and host information are enough.
Could you please provide the sample code snippet that you are using? I just tested the below code with a local WinSSHD server and it worked without any problem. The same information when provided to FileZilla client, it worked as well.
string host = “192.168.0.10”;
int port = 22;
AuthenticationInfo authenticationInfo = new AuthenticationInfo();
authenticationInfo.UserName = “My Username”;
authenticationInfo.Password = “my password”;
// I did not used key file, as my account does not require it
SftpClient client = new SftpClient();
client.Connect(host, port, authenticationInfo);
Hi