SHARE
TWEET

Untitled

a guest Jun 15th, 2017 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public static void upload_sftp(String filename)
  2. {
  3.     String host="hostname.goeshere.com";
  4.     String username="username";
  5.     String password ="password";
  6.     var workingdirectory = "./subfolder";
  7.     String uploadFile = @"c:\\abc.txt";
  8.     int port=22; //default value for SFTP client
  9.     using (var client = new SftpClient(host, port, username, password))
  10.     {
  11.         client.Connect();
  12.         if (client.IsConnected)
  13.         {
  14.             Console.WriteLine("Connected");
  15.             client.ChangeDirectory(workingdirectory);
  16.             using (var fileStream = new FileStream(uploadFile, FileMode.Open))
  17.             {
  18.                 client.BufferSize = 4 * 1024;
  19.                 client.UploadFile(fileStream, filename); // if the same file name as from uploadfile -  Path.GetFileName(uploadfile)
  20.             }
  21.         }
  22.         else
  23.         {
  24.             Console.WriteLine("Not Connected");
  25.         }
  26.     }
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top