I have below a piece of code.
ForEach($line in $lines){
Try
{
$file = "C:\brivo\" + $line
$ftpuri = "ftp://administrator:[email protected]/divyesh/" + $line
$webclient = New-Object System.Net.WebClient
$uri = New-Object System.Uri($ftpuri)
$webclient.DownloadFile($uri,$file)
}
Catch [Exception]
{
Write-Host $_.Exception | format-list -force
}
}
For the details of $lines when I run
$lines.GetType()
$lines
it is displaying like below.
IsPublic IsSerial Name BaseType
-------- -------- ---- --------
True True Collection`1 System.Object
Divyeshwewetwe.json
$file = "C:\brivo$($line)" line generating error every time I run this code with different options. like
$file = ("C:\brivo\" + $line)
and
$file = "C:\brivo\" + $line
it is giving me the below error every time.
System.Net.WebException: An exception occurred during a WebClient request. --->
System.ArgumentException: Illegal characters in
path.
When I give a static file name static then it is working fine like below.
$file = "C:\brivo\123.json"
$line?$line.$linethat are not valid if ftp uris. Add something likewrite-host “ftp uri = ‘$ftpuri’”and show us the output.