It's been already 3 days since I find myself stuck. I have no experience with power shell and also no experience with proxy settings.
My problem is: I'm trying to run the following script from a machine behind a proxy (PAC file settings) which I cannot alter or make an exception.
The result I'm getting with this script - is the bulk HTML informing me that I've reached the server and plenty of unnecessarily HTML tags, images... and somewhere at the end my .zip files (there are only 2 zip files).
Is there any chance to get only the files (in the same way that this script performs on my personal machine (no proxy)) ?
Thanks in advance!
$Global:source = "FTPaddress"
$Global:target = "C:\LocalFolder"
Function Get-FTP{
function Get-FTPDir{
$request = [Net.WebRequest]::Create($Global:source)
$request.Method = [System.Net.WebRequestMethods+FTP]::ListDirectory
$response = $request.GetResponse()
$reader = New-Object IO.StreamReader $response.GetResponseStream()
$reader.ReadToEnd()
$reader.Close()
$response.Close()
}
if(!(Test-Path -Path $Global:target )){
New-Item -ItemType directory -Path $Global:target
}
$WebClient = New-Object System.Net.WebClient
$files=Get-FTPDir | Out-String
$files = $files.replace("`r",",")
$files = $files.replace("`n","")
$files = $files.trimend(",")
$array = $files -split ","
Foreach ($file in ($array | where {$_ -Like "*.xml"})){
if ($file -eq "." -Or $file -eq ".." )
{
continue
}
Write-Host "$file"
$source=$Global:source+$file
$target=$Global:target+$file
$WebClient.DownloadFile($source, $target)
Write-Host "Downloaded: $file"
}
}
Get-FTP