Hi,
We have an intermittent issue where the SFTP fails when we use the Public Private key mode of authentication.
Below is the code snippet which is used to connect to SFTP.
using(Renci.SshNet.SftpClient sftpClient = new Renci.SshNet.SftpClient( AppConfigHelper.Axway_FTPServer,
AppConfigHelper.Axway_FTPUserName,
new Renci.SshNet.PrivateKeyFile[] {
new Renci.SshNet.PrivateKeyFile(File.OpenRead(AppConfigHelper.PrivateKeyFilePath), AppConfigHelper.Passphrase)
}))
{
try
{
sftpClient.Connect();
sftpClient.ChangeDirectory(AppConfigHelper.Axway_UploadFolderName);
using (FileStream fs = new FileStream(fileNameWithPath, FileMode.Open))
{
sftpClient.UploadFile(fs, completeFileName);
LogHelper.LogInfo(string.Format("File {0} uploaded successfully",completeFileName));
}
}
catch (Exception ex)
{
LogHelper.LogInfo(string.Format("File {0} upload failed", completeFileName));
}
finally
{
if (sftpClient != null)
{
if (sftpClient.IsConnected)
sftpClient.Disconnect();
sftpClient.Dispose();
}
}
}
The issue is very intermittent (happens only once in maybe 50 times or 100 times) and doesn't happen at all when we use the password mode of authentication (So we want to know what is wrong with the Public Private key mode of authentication).
For some reason it is not able to connect to the SFTP server and throws the error "Permission Denied".
When I check for sftpClient.IsConnected, sftpClient.ConnectionInfo.IsAuthenticated, both are false when the SFTP fails.
Kindly let us know if there is a suggestion/solution/work around for this problem.
Thanks & Regards,
Sindoor
Sindhoor.bj@gmail.com
Comments: ** Comment from web user: da_rinkes **
We have an intermittent issue where the SFTP fails when we use the Public Private key mode of authentication.
Below is the code snippet which is used to connect to SFTP.
using(Renci.SshNet.SftpClient sftpClient = new Renci.SshNet.SftpClient( AppConfigHelper.Axway_FTPServer,
AppConfigHelper.Axway_FTPUserName,
new Renci.SshNet.PrivateKeyFile[] {
new Renci.SshNet.PrivateKeyFile(File.OpenRead(AppConfigHelper.PrivateKeyFilePath), AppConfigHelper.Passphrase)
}))
{
try
{
sftpClient.Connect();
sftpClient.ChangeDirectory(AppConfigHelper.Axway_UploadFolderName);
using (FileStream fs = new FileStream(fileNameWithPath, FileMode.Open))
{
sftpClient.UploadFile(fs, completeFileName);
LogHelper.LogInfo(string.Format("File {0} uploaded successfully",completeFileName));
}
}
catch (Exception ex)
{
LogHelper.LogInfo(string.Format("File {0} upload failed", completeFileName));
}
finally
{
if (sftpClient != null)
{
if (sftpClient.IsConnected)
sftpClient.Disconnect();
sftpClient.Dispose();
}
}
}
The issue is very intermittent (happens only once in maybe 50 times or 100 times) and doesn't happen at all when we use the password mode of authentication (So we want to know what is wrong with the Public Private key mode of authentication).
For some reason it is not able to connect to the SFTP server and throws the error "Permission Denied".
When I check for sftpClient.IsConnected, sftpClient.ConnectionInfo.IsAuthenticated, both are false when the SFTP fails.
Kindly let us know if there is a suggestion/solution/work around for this problem.
Thanks & Regards,
Sindoor
Sindhoor.bj@gmail.com
Comments: ** Comment from web user: da_rinkes **
Check the logs of your ssh server.