Guest User

Untitled

a guest
Mar 15th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.20 KB | None | 0 0
  1. {
  2.  
  3.  
  4. static void Main(string[] args)
  5. {
  6. const string host = "xxxx";
  7. const string username = "xxxx";
  8. const string password = "xxxx";
  9. const string workingdirectory = "xxxx";
  10. const string RemoteFileName = "xxxx";
  11. const int port = 22;
  12.  
  13. Console.WriteLine("Creating Client and Connecting");
  14.  
  15. Stream stream;
  16. using (var client = new SftpClient(host, port, username, password))
  17. {
  18. client.Connect();
  19. Console.WriteLine("Connected to host");
  20.  
  21. client.ChangeDirectory(workingdirectory);
  22. Console.WriteLine("Changed directory to {0}", workingdirectory);
  23.  
  24. var listDirectory = client.ListDirectory(workingdirectory);
  25. Console.WriteLine("Listing directory:");
  26. foreach (var fi in listDirectory)
  27. {
  28. Console.WriteLine(" - " + fi.Name);
  29. }
  30.  
  31. stream = new MemoryStream();
  32. client.DownloadFile(RemoteFileName, stream);
  33.  
  34. client.Disconnect();
  35. }
  36.  
  37. if (stream != null)
  38. {
  39. if (!stream.CanSeek)
  40. {
  41. throw new Exception("Won't work :(");
  42. }
Add Comment
Please, Sign In to add comment