Post a reply

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)


Topic review


Hello Martin,

Thank you for your reply! Yeah, I saw those articles, but I still have difficulties to understand where to add FTP mode into above PowerShell code:
Set SessionOptions.FtpMode to FtpMode.Passive for on or FtpMode.Active for off.
Enumeration syntax in PowerShell is like [WinSCP.FtpMode]::Passive.

Can you please help out where to add it in order to determine Active or Passive mode?


Where to add -passive=on|off into a PowerShell WinSCP script


I need help! I am trying to understand where to add -passive=on|off parameter into a WinSCP PowerShell script. This is my code:
#Set up session options
$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = $FTPpath
    UserName = $user
    Password = $pass
    SshHostKeyFingerprint = $fingerprint
$sessionOptions.AddRawSettings("KEX", "dh-group1-sha1,ecdh,dh-gex-sha1,dh-group14-sha1,rsa,WARN")
$sessionOptions.AddRawSettings("FSProtocol", "2")
$session = New-Object WinSCP.Session
#Download files
$transferOptions = New-Object WinSCP.TransferOptions
$transferOptions.TransferMode = [WinSCP.TransferMode]::Binary
$remotePath = Split-Path -Path $FilesToRetrieve -Parent
Write-Host "Remote Path is $remotePath"
# Get list of files in the directory
$directoryInfo = $session.ListDirectory($remotePath)
# Select the most recent file
$latest = $directoryInfo.Files |
Where-Object LastWriteTime -gt (Get-Date).AddDays(-$LastWriteTimeDays)
Write-Host "LastWriteTime is $latest"

Can someone help out where I can add the parameter in my code so I can turn off or on passive mode?

Thanks in advance!