Link to home
Create AccountLog in
Avatar of jimmylew52
jimmylew52Flag for United States of America

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($source, $target)
}

Exception calling "DownloadFile" with "2" argument(s): "An exception occurred d
uring a WebClient request."
At E:\FTP_Test\FTP_Test.ps1:54 char:24
+ $WebClient.DownloadFile <<<< ($source, $target)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException
ASKER CERTIFIED SOLUTION
Avatar of SubSun
SubSun
Flag of India image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of jimmylew52

ASKER

Thanks again for the help