Guest User

Untitled

a guest
Apr 16th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. WebClient webClient = new WebClient();
  2. Log("Downloading File from web...");
  3. try
  4. {
  5. webClient.DownloadFile(new Uri(uri), downloadLocation);
  6. Log("Download from web complete");
  7. webClient.Dispose();
  8. }
  9. catch (Exception ex)
  10. {
  11. Log("Error Occurred in downloading file. See below for exception details");
  12. Log(ex.Message);
  13. webClient.Dispose();
  14. }
  15.  
  16. // Setup session options
  17. SessionOptions sessionOptions = new SessionOptions
  18. {
  19.  
  20. Protocol = Protocol.Sftp,
  21. HostName = ConfigurationManager.AppSettings["scpurl"],
  22. UserName = ConfigurationManager.AppSettings["scpuser"],
  23. Password = ConfigurationManager.AppSettings["scppass"].Trim(),
  24. SshHostKeyFingerprint = ConfigurationManager.AppSettings["scprsa"].Trim()
  25. };
  26.  
  27. using (Session session = new Session())
  28. {
  29.  
  30. //disable version checking
  31. session.DisableVersionCheck = true;
  32.  
  33. // Connect
  34. session.Open(sessionOptions);
  35.  
  36. // Upload files
  37. TransferOptions transferOptions = new TransferOptions();
  38. transferOptions.TransferMode = TransferMode.Binary;
  39.  
  40. TransferOperationResult transferResult;
  41. transferResult = session.PutFiles(absPathSource, destination, false, transferOptions);
  42.  
  43. // Throw on any error
  44. transferResult.Check();
  45.  
  46. // Print results
  47. foreach (TransferEventArgs transfer in transferResult.Transfers)
  48. {
  49. //Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
  50. }
  51. }
Add Comment
Please, Sign In to add comment