You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to upload file using SFTP. The file gets uploaded sometimes and most the times it throws the error SSH.NET (Permission denied (publickey)) The SFTP server accepts only whitelist IP addresses.
public void SetConnection(string userName, string strRSAKey)
{
var authMethods = new List<AuthenticationMethod>();
authMethods.Add(new PrivateKeyAuthenticationMethod(
userName,
new[] { new PrivateKeyFile(GenerateStream(strRSAKey)) }
));
connectionInfo = new ConnectionInfo(hostName, port, userName, authMethods.ToArray());
}
public bool UploadFile(string sourceFilePath, string destinationFilePath)
{
if (connectionInfo != null)
{
using (var client = new SftpClient(connectionInfo))
{
client.Connect();
if (client.IsConnected)
{
var csvFile = File.Open(sourceFilePath, FileMode.Open);
client.UploadFile(csvFile, destinationFilePath, true);
csvFile.Dispose();
}
client.Disconnect();
return true;
}
}
return false;
}
private Stream GenerateStream(string str)
{
var stream = new MemoryStream();
var writer = new StreamWriter(stream);
writer.Write(str);
writer.Flush();
stream.Position = 0;
return stream;
}
The text was updated successfully, but these errors were encountered:
I am trying to upload file using SFTP. The file gets uploaded sometimes and most the times it throws the error SSH.NET (Permission denied (publickey)) The SFTP server accepts only whitelist IP addresses.
The text was updated successfully, but these errors were encountered: