Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2015
235
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. http://samplesite.com/sample1/image1.jpg
  2.  
  3. try
  4. {
  5. # Load WinSCP .NET assembly
  6. Add-Type -Path "WinSCPnet.dll"
  7.  
  8. # Setup session options
  9. $sessionOptions = New-Object WinSCP.SessionOptions
  10. $sessionOptions.Protocol = [WinSCP.Protocol]::Sftp
  11. $sessionOptions.HostName = "example.com"
  12. $sessionOptions.UserName = "user"
  13. $sessionOptions.Password = "mypassword"
  14. $sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
  15.  
  16. $session = New-Object WinSCP.Session
  17.  
  18. $remoteRoot = "/home/user"
  19.  
  20. try
  21. {
  22. # Connect
  23. $session.Open($sessionOptions)
  24.  
  25. foreach ($line in [System.IO.File]::ReadLines("list.txt"))
  26. {
  27. if ($line -Match "http://[a-z.]+(/(.*)/[a-z0-9.]+)$")
  28. {
  29. $remotePath = $matches[1]
  30. $remoteDir = $matches[2]
  31. $localDir = $remoteDir -Replace "/", ""
  32.  
  33. if (!(Test-Path $localDir))
  34. {
  35. Write-Host "Creating directory $localDir"
  36. New-Item $localDir -Type directory | Out-Null
  37. }
  38.  
  39. Write-Host "Downloading $remotePath"
  40. $session.GetFiles(($remoteRoot + $remotePath), ($localDir + "")).Check()
  41. }
  42. else
  43. {
  44. Write-Host "$line does not have expected URL format"
  45. }
  46. }
  47. }
  48. finally
  49. {
  50. # Disconnect, clean up
  51. $session.Dispose()
  52. }
  53.  
  54. exit 0
  55. }
  56. catch [Exception]
  57. {
  58. Write-Host $_.Exception.Message
  59. exit 1
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement