This is an old revision of the document!

open

Establishes new connection.

Advertisement

Syntax

open <session_url>
open <site>

Remarks

Establishes connection to given host. Use session URL or name of the site. To open site, stored in folder, use path syntax “folder/site”. Using session URL is preferred as it makes your script independent on the persisted configuration. With session URL, you typically specify a protocol, host name, username and password, optionally also a port number and SSH host key fingerprint.

You can use Generate Session URL/Code command to generate the open command for a given stored site. This feature is available only in the latest beta release.

Note that to allow the session be opened automatically without interaction, you need to make sure you provide all details, including all credentials. Generally, you need to provide a password in your session URL or site. With SSH you may alternatively use private key. With SSH, FTPS or WebDAVS you need to verify the host or certificate.

Switches:

Switch Description
-privatekey=<file> SSH private key path.
SFTP and SCP protocols only.
-hostkey="<fingerprint>" Specifies fingerprint of expected SSH host key (or several alternative fingerprints separated by semicolon). It makes WinSCP automatically accept host key with the fingerprint. As the host key fingerprint contains spaces you need to surround it by quotes. Learn how to obtain host key fingerprint.
In exceptional situations, when security is not required, you can use value * to accept any host key. In this case, script output and log file will include warning about insecure connection.
SFTP and SCP protocols only.
-clientcert=<file> TLS/SSL client certificate path. This feature is available only in the latest beta release.
FTPS and WebDAVS protocols only.
-certificate="<fingerprint>" Specifies fingerprint of expected TLS/SSL certificate (or several fingerprints separated by semicolon). It makes WinSCP automatically accept certificate with the fingerprint.
In exceptional situations, when security is not required, you can use value * to accept any certificate. In this case, script output and log file will include warning about insecure connection.
FTPS and WebDAVS protocols only.
-passphrase=<phrase> Passphrase for encrypted private keys and client certificates.
SFTP, SCP, FTPS and WebDAVS protocols only.
-passive=on|off Enables passive (=on) or active (=off) transfer mode (FTP protocol only).
-implicit Implicit TLS/SSL (FTPS protocol only)
-explicit Explicit TLS/SSL (FTPS protocol only).
-timeout=<sec> Server response timeout
-rawsettings setting1=value1 setting2=value2 Allows configuring any site settings using raw format as in an INI file. E.g. to enable SSH compression and agent forwarding use -rawsettings Compression=1 AgentFwd=1. The switch must come after session URL.
-filezilla Load site from FileZilla site manager.1
Additionally it prints a full syntax to use to open an identical session without relying on an external FileZilla configuration. This feature is available only in the latest beta release.

Advertisement

XML log element: session

Examples

open sftp://martin:mypassword@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
open scp://test@example.com:2222/ -privatekey=mykey.ppk
open ftps://martin:mypassword@example.com/ -implicit -certificate="xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
open sftp://martin:mypassword@example.com/ -rawsettings ProxyMethod=3 ProxyHost=proxy
open sftp://martin@example.com/
open sftp://example.com/
open ftp://martin:mypassword@example.com/

Converting to .NET Assembly

When converting script to .NET Assembly, map open command to Session.Open method. The Session.Open accepts instance of SessionOptions class, which needs to be populated according to parameters and switches of open command.

Parameters mapping: Session URL in command parameter session_url needs to be separated to its components, which are to be stored into SessionOptions.HostName (host component), SessionOptions.UserName (username), SessionOptions.Password (password), SessionOptions.PortNumber (port) and SessionOptions.Protocol (sftp|ftp|ftps|ftpes|http|https|scp://2).

There is no direct mapping for opening stored site using site parameter, because .NET assembly does not share configuration with graphical/scripting mode. You need to configure all your site settings directly in your code (using SessionOptions class).

Switches mapping:

Switch Mapping
-privatekey Set SessionOptions.SshPrivateKeyPath.
-hostkey Set SessionOptions.SshHostKeyFingerprint.
-clientcert Set SessionOptions.TlsClientCertificatePath.
-certificate Set SessionOptions.TlsHostCertificateFingerprint.
-passphrase Set SessionOptions.SshPrivateKeyPassphrase.
-passive Set SessionOptions.FtpMode to FtpMode.Passive for on or FtpMode.Active
Enumeration syntax in PowerShell is like [WinSCP.FtpMode]::Passive.
-implicit Set SessionOptions.FtpSecure to FtpSecure.Implicit ([WinSCP.FtpSecure]::Implicit in PowerShell).
-explicit Set SessionOptions.FtpSecure to FtpSecure.Explicit ([WinSCP.FtpSecure]::Explicit).
-timeout Set SessionOptions.Timeout.
-rawsettings Call SessionOptions.AddRawSettings for every key/value pair in switch parameters.
-filezilla Convert the full equivalent syntax suggested, when the open command is executed.

Advertisement

For example, following script snippet:

open sftp://martin:mypassword@example.com/ -hostkey="ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"

maps to following PowerShell code:

$sessionOptions = New-Object WinSCP.SessionOptions -Property @{
    # sftp://
    Protocol = [WinSCP.Protocol]::Sftp
    HostName = "example.com"
    UserName = "martin"
    Password = "mypassword"
    # -hostkey
    SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
}
 
$session = New-Object WinSCP.Session
# Connect
$session.Open($sessionOptions)
  1. WinSCP looks for sites in C:\Users\username\AppData\Roaming\FileZilla\sitemanager.xml. Back
  2. For https://, use SessionOptions.Protocol = Protocol.Webdav and SessionOptions.WebdavSecure = true.Back

Last modified: by Petr