Skip to content

Instantly share code, notes, and snippets.

@jorgepsmatos
Last active August 22, 2019 22:43
Show Gist options
  • Save jorgepsmatos/85fd7657cab07683fe70eabfa440f4a1 to your computer and use it in GitHub Desktop.
Save jorgepsmatos/85fd7657cab07683fe70eabfa440f4a1 to your computer and use it in GitHub Desktop.
public void Upload(string fileToUpload, string host, string username, string password)
{
try
{
using (var sftpClient = new SftpClient(host, username, password))
using (var fs = new FileStream(fileToUpload, FileMode.Open))
{
sftpClient.Connect();
sftpClient.UploadFile(
fs,
"/ftproot/" + Path.GetFileName(fileToUpload),
uploaded =>
{
Console.WriteLine($"Uploaded {(double)uploaded / 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