Guest User

Untitled

a guest
Oct 4th, 2018
575
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.09 KB | None | 0 0
  1. $ftp = "ftp://ftp3.example.com/Jaz/In/"
  2. $user = 'username'
  3. $pass = 'password'
  4. $folder = "/"
  5. $target = "C:UsersJasdeepDestination"
  6.  
  7. $credentials = new-object System.Net.NetworkCredential($user, $pass)
  8.  
  9. function Get-FtpDir ($url,$credentials) {
  10. $request = [Net.WebRequest]::Create($url)
  11. $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
  12. if ($credentials) { $request.Credentials = $credentials }
  13. $response = $request.GetResponse()
  14. $reader = New-Object IO.StreamReader $response.GetResponseStream()
  15. $reader.ReadToEnd()
  16. $reader.Close()
  17. $response.Close()
  18. }
  19.  
  20. $folderPath= $ftp + "/" + $folder + "/"
  21.  
  22. $Allfiles=Get-FTPDir -url $folderPath -credentials $credentials
  23. $files = ($Allfiles -split "`r`n")
  24.  
  25. $files
  26.  
  27. $webclient = New-Object System.Net.WebClient
  28. $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
  29. $counter = 0
  30. foreach ($file in ($files | where {$_ -like "*.*"})){
  31. $source=$folderPath + $file
  32. $destination = $target + $file
  33. $webclient.DownloadFile($source, $target+$file)
  34.  
  35. $counter++
  36. $counter
  37. $source
  38. }
Add Comment
Please, Sign In to add comment