This is an old revision of the document!

Session URL

On command-line and in parameter of scripting command open, you can specify basis session settings using session URL.

In WinSCP .NET assembly, you can use session URL too as an alternative way to provide session options. Use method SessionOptions.ParseUrl.

To ease assembling the URL, you can have WinSCP generate it for you.

Advertisement

Syntax

<protocol> :// [ <username> [ : <password> ] [ ; <advanced> ] @ ] <host> [ : <port> ] /

focusonwomenmagazine.net ftps https winscp- focusonwomenmagazine.net 21 for ftp

Advanced Settings

A session URL can optionally set any advanced session settings using a syntax based on raw site settings.

Providing advanced settings in the session URL is mainly useful, if you need to provide all session settings using URL only, such as using a hyperlink on a web page; or when you want to serialize all session settings into a single “connection string”, such as when passing the current setting settings to a WinSCP extension.

Advertisement

A syntax to serialize raw site settings is ;x-name1=value1;x-name2=value2 (inserted after username and password).

For example to use an HTTP proxy server proxy, use the following URL:
sftp://username:password;x-proxymethod=3;x-proxyhost=proxy@example.com/

To have WinSCP generate a session URL with the advanced settings, check Advanced settings on Generate session URL/code dialog. To serialize all session settings for a WinSCP extension, use !E pattern.

SSH Host Key Fingerprint

There’s a special syntax to include an expected SSH host key fingerprint in SFTP/SCP URL among advanced site settings: fingerprint=<fingerprint>.

For security reasons, fingerprint provided in session URL does not override any fingerprint already cached on the machine. This for instance differs from behavior, when fingerprint is provided using -hostkey switch of open command in scripting.

Format of the fingerprint for URL1 somewhat differs from format used in other WinSCP features (-hostkey switch of open command in scripting for instance). To convert WinSCP fingerprint format to URL format:

  1. Drop bit count part (the number after ssh-rsa or ssh-dss, typically 2048 or 1024);
  2. Replace the remaining space with a dash sign (-).2
  3. Pluses (+) and slashes (/) in SHA-256 hash need to be encoded or replaced with dashes (-) and underscores (_) respectively (the latest beta version only).

For example WinSCP fingerprint ssh-rsa 2048 2EP3avJqmpRtSRaUIqwrzavm15vssrhHxJWh9mBaz8M= converts to ssh-rsa-2EP3avJqmpRtSRaUIqwrzavm15vssrhHxJWh9mBaz8M=.

Special Characters

Special characters (like @ in username, see example below) have to be encoded using %XX syntax, where XX is hexadecimal UTF-8 code.3

Common special characters are:

  • space: %20 or +
  • #: %23 (number sign/hash)
  • %: %25 (percent sign)
  • +: %2B (plus sign)
  • /: %2F (slash)
  • @: %40 (at sign)
  • :: %3A (colon)
  • ;: %3B (semicolon)

Note that when specifying session URL on command-line, you cannot use characters that have special meaning on Windows command-line, just as with any other command-line argument. Such characters include & (ampersand), | (pipe), < (less-than sign), > (greater-than sign), " (double-quote). To escape these characters, you can wrap whole session URL to double-quotes (") or encode the characters as shown above.

Advertisement

Further, in Windows batch files, % (percent sign) needs to be doubled to be used correctly, even when the sign is itself used to encode other special characters. For example, to use @ in a username, specify %%40.

You can have WinSCP generate correct URL for all kinds of uses (command-line, script or batch file).

Examples

sftp://martin:mypassword@example.com/
sftp://root@example.com:2222/
ftp://127.0.0.1:2121/
ftp://[2001:db8:85a3:8d3:1319:8a2e:370:7348]:2121/
sftp://martin;fingerprint=ssh-rsa-2EP3avJqmpRtSRaUIqwrzavm15vssrhHxJWh9mBaz8M=@example.com/
http://martin@example.com/dav/

Directory or File URL

A URL specified on command-line can include an initial remote path (the path has to end with a slash):
sftp://username@example.com/remote/path/

You can also include a file path into the URL:
sftp://username@example.com/remote/path/file.txt

By default, it will initiate the file download. When combined with /browse switch, the file will instead be selected in a file panel.

Other Uses

You can also paste session URL on Login dialog or main window or even Windows File Explorer or web browser (if WinSCP is registered to handle file transfer protocol URL addresses).

You can use custom command patterns !E or !S to pass a session URL to other processes.

  1. Fingerprint format for URL is based on draft-ietf-secsh-scp-sftp-ssh-uri.Back
  2. In case you are still using MD5 fingerprints, replace all colons (:) with a dash sign (-) too. Though you should switch to SHA-256 fingerprints.Back
  3. For multi-byte codes, use % before every byte, for instance to represent pound-sign £ use %C2%A3.Back

Last modified: by 183.83.145.3