I am working on a tool to download files from SFTP, 2 at a time. I am using Tamir.Sharpssh to connect to the SFTP, and I thought it would be do-able by using async and await. When I run the program, it finishes with no errors but I am not seeing any files downloaded.
Below is my code, thank you in advance!
private async static void SFTPFileGetHelper()
{
try
{
Task<String> task1 = GetFileAsync(sftpFile1, localFile1);
Task<String> task2 = GetFileAsync(sftpFile2, localFile2);
await Task.WhenAll(task1, task2);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
public static Task<String> GetFileAsync(string remoteFilePath, string localFilePath)
{
return (Task.Run(() =>
{
try
{
Sftp conn = new Sftp(Host, Username, Password);
conn.Connect();
conn.Get(remoteFilePath, localFilePath);
conn.Close();
return remoteFilePath;
}
catch(Exception ex)
{
return ex.Message;
}
}));
}