Advertisement
Guest User

Untitled

a guest
Jun 15th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement