Error connexion : Connecting to FTP error

Advertisement

steph07
Joined:
Posts:
4

Error connexion : Connecting to FTP error

Hello,

I have a problem scripting.
this is the script :

# Specify directories
$localPath = "C:\Temp\script"
$remotePath =  "/test"
 
    # Load WinSCP .NET assembly
Add-Type -Path "C:\Program Files (x86)\WinSCP\WinSCPnet.dll"
 
 
try
{
 
    # Setup session options
    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::ftp
        HostName = "eportal-scheduled.services.xxxx.com"
        UserName = "eportal-ftp@anonyme.fr"
        Password = "xxxxxxxx*B"
    }
 
    $session = New-Object WinSCP.Session
 
    try
    {
        # Connect
        Write-Host "Connecting to FTP..."
        $session.Open($sessionOptions)
 
        # Download files
        $transferOptions = New-Object WinSCP.TransferOptions
        $transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
         
        Write-Host "Synchronizing changes..."
        $transferResult =
            $session.SynchronizeDirectories(
                  [WinSCP.SynchronizationMode]::Local, $localPath, $remotePath, $false. $transferOptions)
 
        # Throw on any error
        $transferResult.Check()
 
        # Print results
        foreach ($transfer in $transferResult.Downloads)
        {
            Write-Host "Download of $($transfer.FileName) succeeded"
        }
    }
    finally
    {
        # Disconnect, clean up
        $session.Dispose()
    }
 
    exit 0
}
catch
{
    Write-Host "Error: $($_.Exception.Message)"
    exit 1
}

I have the result :

Connecting to FTP...
Error: Exception calling "Open" with "1" argument(s): "Connection failed.
Connection failed.
Sorry, cleartext sessions are not accepted on this server.
Please reconnect using SSL/TLS security mechanisms."

Can you help

Best Regards
Stephane

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,587
Location:
Prague, Czechia

Re: Error connexion : Connecting to FTP error

To enable SSL/TLS, set SessionOptions.FtpSecure:
https://winscp.net/eng/docs/library_sessionoptions#ftpsecure

    $sessionOptions = New-Object WinSCP.SessionOptions -Property @{
        Protocol = [WinSCP.Protocol]::ftp
        HostName = "eportal-scheduled.services.xxxx.com"
        UserName = "eportal-ftp@anonyme.fr"
        Password = "xxxxxxxx*B"
        FtpSecure = [WinSCP.FtpSecure]::Explicit
    }
You might also need to set SessionOptions.TlsHostCertificateFingerprint.

Reply with quote

steph07
Joined:
Posts:
4

Error connexion : Connecting to FTP error

Thank you Martin, it works now.

But sometimes, i have this error :

Error: Exception calling "Check" with "0" argument(s): "Error transferring file '/.ftpquota'.
Copying files from remote side failed.
Prohibited file name: .ftpquota"

I search to google this error "Prohibited file name: .ftpquota" but i didn't find anything.

Stéphane

Reply with quote

martin
Site Admin
martin avatar

Re: Error connexion : Connecting to FTP error

That's not WinSCP message. It must come from your server.
If you cannot upload that file, you need to exclude it from the synchronization.

Reply with quote

Advertisement

You can post new topics in this forum