Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ftp = "ftp://ftp3.example.com/Jaz/In/"
- $user = 'username'
- $pass = 'password'
- $folder = "/"
- $target = "C:UsersJasdeepDestination"
- $credentials = new-object System.Net.NetworkCredential($user, $pass)
- function Get-FtpDir ($url,$credentials) {
- $request = [Net.WebRequest]::Create($url)
- $request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
- if ($credentials) { $request.Credentials = $credentials }
- $response = $request.GetResponse()
- $reader = New-Object IO.StreamReader $response.GetResponseStream()
- $reader.ReadToEnd()
- $reader.Close()
- $response.Close()
- }
- $folderPath= $ftp + "/" + $folder + "/"
- $Allfiles=Get-FTPDir -url $folderPath -credentials $credentials
- $files = ($Allfiles -split "`r`n")
- $files
- $webclient = New-Object System.Net.WebClient
- $webclient.Credentials = New-Object System.Net.NetworkCredential($user,$pass)
- $counter = 0
- foreach ($file in ($files | where {$_ -like "*.*"})){
- $source=$folderPath + $file
- $destination = $target + $file
- $webclient.DownloadFile($source, $target+$file)
- $counter++
- $counter
- $source
- }
Add Comment
Please, Sign In to add comment