SFTP Connection - Session.Open; ERROR: Temporary File in use
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll Additional information: The process cannot access the file 'C:\Users\Admin\AppData\Local\Temp\wscp24C0.0223CC89.tmp' because it is being used by another process.
Here is the code:
private bool uploadFile(string path, string hostName, string username, string password)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = hostName,
UserName = username,
Password = password,
SshHostKeyFingerprint = "ssh-rsa 1024 **:**:**:**:20:8f:95:69:12:f5:52:**:**:**:**:**"
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = session.PutFiles(path, "/", false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}
return true;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return false;
}
}