Guest User

Untitled

a guest
Oct 24th, 2017
724
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. winscp.com /ini=nul /command ^
  2. "open sftp://username:password;fingerprint=hostkeyfingerprint@example.com/" ^
  3. "put -filemask=*>=%%TIMESTAMP#yyyy-mm-dd%% ""c:localpath*"" ""/remote/path/""" ^
  4. "exit"
  5.  
  6. string winscpPath = Dts.Variables["winSCPPath"].Value.ToString();
  7. string username = Dts.Variables["ftpUsername"].Value.ToString();
  8. string password = Dts.Variables["ftpPassword"].Value.ToString();
  9. string ftpSite = Dts.Variables["ftpSite"].Value.ToString();
  10. string localPath = Dts.Variables["localPath"].Value.ToString();
  11. string remoteFTPDirectory = Dts.Variables["remoteFTPDirectory "].Value.ToString();
  12. string sshKey = Dts.Variables["sshKey"].Value.ToString();
  13. Boolean winSCPLog = (Boolean)Dts.Variables["winSCPLog"].Value;
  14. string winSCPLogPath = Dts.Variables["winSCPLogPath"].Value.ToString();
  15.  
  16. SessionOptions sessionOptions = new SessionOptions
  17. {
  18. Protocol = Protocol.Sftp,
  19. HostName = ftpSite,
  20. UserName = username,
  21. Password = password,
  22. SshHostKeyFingerprint = sshKey
  23. };
  24.  
  25. try
  26. {
  27. using (Session session = new Session())
  28. {
  29. // WinSCP .NET assembly must be in GAC to be used with SSIS,
  30. // set path to WinSCP.exe explicitly, if using non-default path.
  31. session.ExecutablePath = winscpPath;
  32. session.DisableVersionCheck = true;
  33.  
  34. if(winSCPLog)
  35. {
  36. session.SessionLogPath = @winSCPLogPath + @"WinscpSessionLog.txt";
  37. session.DebugLogPath = @winSCPLogPath + @"WinscpDebugLog.txt";
  38. }
  39.  
  40. // Connect
  41. session.Timeout = new TimeSpan(0,2,0); // two minutes
  42. session.Open(sessionOptions);
  43.  
  44. TransferOptions transferOptions = new TransferOptions();
  45. transferOptions.TransferMode = TransferMode.Binary;
  46.  
  47. try
  48. {
  49. session.GetFiles(remoteFTPDirectory + "/" +
  50. fileToDownload, localPath, false, transferOptions);
  51. }
  52. catch (Exception e)
  53. {
  54. Dts.Events.FireError(0, null,
  55. string.Format("Error when using WinSCP to download file: {0}", e), null, 0);
  56. Dts.TaskResult = (int)DTSExecResult.Failure;
  57. }
  58. }
  59. }
  60. Dts.TaskResult = (int)ScriptResults.Success;
Add Comment
Please, Sign In to add comment