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

Advertisement

stijacicn
Joined:
Posts:
3
Location:
sweden

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

Hello,

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
 
#Connect
$session.Open($sessionOptions)
 
#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!

Regards,
Nikola

Reply with quote

Advertisement

stijacicn
Joined:
Posts:
3
Location:
sweden

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
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?

Thanks!

Reply with quote

Advertisement

You can post new topics in this forum