jimmylew52
asked on
Powershell script to download a list of files from FTP
I have been working on a script to download files from a FTP server. I have a text file that contains the list of file names to download - filenames.txt. When I run the script I get the error below. Can anyone till me what I have done wrong. Searches on the internet have not been helpful.
$URL = "ftp://FTPTest:Green4321@10.70.1.25/"
$Local + "E:\FTPTest\"
ForEach($FTP_File in Get-Content E:\FTP_Test\FileNames.txt) {
$source = $URL + $FTP_File
$target = $Local + $FTP_File
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($s ource, $target)
}
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred d
uring a WebClient request."
At E:\FTP_Test\FTP_Test.ps1:5 4 char:24
+ $WebClient.DownloadFile <<<< ($source, $target)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
$URL = "ftp://FTPTest:Green4321@10.70.1.25/"
$Local + "E:\FTPTest\"
ForEach($FTP_File in Get-Content E:\FTP_Test\FileNames.txt)
$source = $URL + $FTP_File
$target = $Local + $FTP_File
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($s
}
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred d
uring a WebClient request."
At E:\FTP_Test\FTP_Test.ps1:5
+ $WebClient.DownloadFile <<<< ($source, $target)
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : DotNetMethodException
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER