Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <#
- .PARAMETER username
- Username
- .PARAMETER password
- Password
- .PARAMETER Ftpsite
- Ftpsite, must contain ftp://
- ftp://ftps.****.****
- .PARAMETER Folder
- The folder the script will look in.
- $Folder = "Hogia_svc"
- Or multiple
- $Folder = "Best_svc", "Hogia_svc"
- .PARAMETER Output
- Output folder i.e. C:\temp
- .NOTES
- (C) Molnbolaget Sverige AB
- #>
- $Ftpsite = "ftp://"
- $username = ""
- $password = ""
- [string[]]$folder = "Order/IN"
- $output = "C:\Junk\"
- function New-Ftpdownload ($Ftpsite, $credentials) {
- $credentials = new-object System.Net.NetworkCredential($username, $password)
- $request = [Net.WebRequest]::Create($Ftpsite)
- $request.UsePassive = $true
- $request.UseBinary = $true
- $request.EnableSsl = $true
- $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
- if ($credentials) { $request.Credentials = $credentials }
- $response = $request.GetResponse()
- $reader = New-Object IO.StreamReader $response.GetResponseStream()
- while (-not $reader.EndOfStream) {
- $reader.ReadLine()
- }
- $reader.Close()
- $response.Close()
- }
- foreach ($f in $folder) {
- $folderPath = $Ftpsite + "/" + $f + "/"
- $files = New-Ftpdownload -Ftpsite $folderPath -credentials $credentials
- $webclient = New-Object System.Net.WebClient
- $webclient.Credentials = New-Object System.Net.NetworkCredential($username, $password)
- foreach ($file in $files) {
- $source = $folderPath + $file
- $destination = $output + $file
- $webclient.DownloadFile($source, $destination)
- Write-output "Downloading $source"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement