Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
9,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <#
  2. .PARAMETER username
  3. Username
  4.  
  5. .PARAMETER password
  6. Password
  7.  
  8. .PARAMETER Ftpsite
  9. Ftpsite, must contain ftp://
  10. ftp://ftps.****.****
  11.  
  12. .PARAMETER Folder
  13. The folder the script will look in.
  14.  
  15. $Folder = "Hogia_svc"
  16. Or multiple
  17. $Folder = "Best_svc", "Hogia_svc"
  18.  
  19. .PARAMETER Output
  20. Output folder i.e. C:\temp
  21.  
  22. .NOTES
  23. (C) Molnbolaget Sverige AB
  24.  
  25. #>
  26. $Ftpsite = "ftp://"
  27. $username = ""
  28. $password = ""
  29. [string[]]$folder = "Order/IN"
  30. $output = "C:\Junk\"
  31.  
  32. function New-Ftpdownload ($Ftpsite, $credentials) {
  33. $credentials = new-object System.Net.NetworkCredential($username, $password)
  34. $request = [Net.WebRequest]::Create($Ftpsite)
  35. $request.UsePassive = $true
  36. $request.UseBinary = $true
  37. $request.EnableSsl = $true
  38. $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
  39. if ($credentials) { $request.Credentials = $credentials }
  40. $response = $request.GetResponse()
  41. $reader = New-Object IO.StreamReader $response.GetResponseStream()
  42. while (-not $reader.EndOfStream) {
  43. $reader.ReadLine()
  44. }
  45. $reader.Close()
  46. $response.Close()
  47. }
  48.  
  49. foreach ($f in $folder) {
  50. $folderPath = $Ftpsite + "/" + $f + "/"
  51.  
  52. $files = New-Ftpdownload -Ftpsite $folderPath -credentials $credentials
  53.  
  54. $webclient = New-Object System.Net.WebClient
  55. $webclient.Credentials = New-Object System.Net.NetworkCredential($username, $password)
  56.  
  57. foreach ($file in $files) {
  58. $source = $folderPath + $file
  59. $destination = $output + $file
  60. $webclient.DownloadFile($source, $destination)
  61.  
  62. Write-output "Downloading $source"
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement