0

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
Bogdan F
  • 5
  • 2
  • yep! @MartinPrikryl you are right! Now I have to convince my boss to allow the installation of WinSCP on the production env. Is there a special setting for configuration of WinSCP FTP connection in this case via proxy? Using power shell scripting (actually I'm building Power automate desktop process) – Bogdan F Jan 21 '22 at 07:24
  • WinSCP GUI can [generate a code template](https://winscp.net/eng/docs/ui_generateurl#code) with all necessary settings for you. If you need further help, please ask a separate question. – Martin Prikryl Jan 21 '22 at 07:43

0 Answers0