Post a reply

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Guest

Re: Connect to ftp via Proxy

nd i'm not sure where to find the full session log files
Guest

Re: Connect to ftp via Proxy

Here is my PowerShell script
param (
    $localPath = "c:\lidar\downloaded\",
    $remotePath = "/Lid/WIPO0100306/average_data/",
    $remotePath2 = "/Nac/T10min/",
    $remotePath3 = "/Tow/T10min/",
    $fileName = "*"
)
 
try
{
    # Load WinSCP .NET assembly
    Add-Type -Path "C:\lidar\WinSCP-5.17.9-Automation\WinSCPnet.dll"
 
    # Setup session options
    $sessionOptions.AddRawSettings("ProxyMethod", "3")
    $sessionOptions.AddRawSettings("ProxyHost", "proxy server ip")
    $sessionOptions.AddRawSettings("ProxyPort", "8080")
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::ftp
        HostName = "ftp server address"
        UserName = "my-username"
        Password = "my-password "
    }
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        $session.Open($sessionOptions)
 
        # Get list of files in the directory
        $directoryInfo = $session.ListDirectory($remotePath)
 
        # Select the most recent file
        $latest =
            $directoryInfo.Files |
            Where-Object { -Not $_.IsDirectory } |
            Sort-Object LastWriteTime -Descending |
            Select-Object -First 1
 
        # Any file at all?
        if ($latest -eq $Null)
        {
            Write-Host "No file found"
            exit 1
        }
 
        # Download the selected file
        $session.GetFiles(
            [WinSCP.RemotePath]::EscapeFileMask($latest.FullName), $localPath).Check()
 
##------------------NEXT FILE PARH ----------------------------------##
 
        # Get list of files in the directory
        $directoryInfo = $session.ListDirectory($remotePath2)
 
        # Select the most recent file
        $latest =
            $directoryInfo.Files |
            Where-Object { -Not $_.IsDirectory } |
            Sort-Object LastWriteTime -Descending |
            Select-Object -First 1
 
        # Any file at all?
        if ($latest -eq $Null)
        {
            Write-Host "No file found"
            exit 1
        }
 
        # Download the selected file
        $session.GetFiles(
            [WinSCP.RemotePath]::EscapeFileMask($latest.FullName), $localPath).Check()
 
##------------------NEXT FILE PARH ----------------------------------##
 
         # Get list of files in the directory
        $directoryInfo = $session.ListDirectory($remotePath3)
 
        # Select the most recent file
        $latest =
            $directoryInfo.Files |
            Where-Object { -Not $_.IsDirectory } |
            Sort-Object LastWriteTime -Descending |
            Select-Object -First 1