Skip to content

Instantly share code, notes, and snippets.

@jorgepsmatos
Created August 22, 2019 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgepsmatos/e73f74e7544ddc3f0fcb34d778f9635b to your computer and use it in GitHub Desktop.
Save jorgepsmatos/e73f74e7544ddc3f0fcb34d778f9635b to your computer and use it in GitHub Desktop.
public void Download(string fileToDownload, string host, string username, string password)
{
try
{
using (var sftpClient = new SftpClient(host, username, password))
using (var fs = new FileStream(Path.GetFileName(fileToDownload), FileMode.OpenOrCreate))
{
sftpClient.Connect();
sftpClient.DownloadFile(
"/ftproot/" + fileToDownload,
fs,
downloaded =>
{
Console.WriteLine($"Downloaded {(double)downloaded / fs.Length * 100}% of the file.");
});
sftpClient.Disconnect();
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment