This is an old revision of the document!

Documentation » Using WinSCP »

Generate Session URL/Code Dialog

Generate session URL/code dialog is used to generate a session URL, a file URL or a code template.

To open the dialog to generate the session URL or code, use:

  • Session > Generate Session URL/Code command on the main window to generate session URL or code template for the current session. (preferred)
  • Manage > Generate Session URL/Code command on the Login dialog to generate session URL or code template for the selected site.

Advertisement

To open the dialog to generate the file URL, use:

  • File(s) > File Names > Generate File URL command on main window to generate file URL for files selected in the remote file panel.

The dialog has three tabs. Each is described individually.

URL Tab

Use the URL tab to generate a session URL or a file URL.

Advertisement

The generated URL always includes a protocol and a host name portions. Other parts can be included optionally.

Check the User name to include username into the URL. The option is not available when the dialog is opened from the Login dialog and the user name was not specified; or (rarely) when the current session did not require the user name.

Check the Password to include password into the URL. Make sure you protect an URL that includes the password appropriately. The option is not available when the dialog is opened from the Login dialog and the password was not specified; or when the current session does not use a password authentication; or when the password was not stored nor remembered.

Check the SSH host key to include an SSH host key fingerprint into the URL. The option is available for an SFTP and an SCP (SSH-based) sessions only. The option may not available when the dialog is opened before the session is connected as the host key may not be known yet. Note that some (most) SSH clients need not understand a session URL that includes the host key fingerprint.

Check the Initial directory to include an initial remote directory into the URL. When the dialog is opened opened from the Login dialog, Remote directory as specified on the Advanced site settings dialog is used. When opened from the main window, the current working remote directory is used. The option is not available when generating an URL for selected file(s) as a path to the file(s) is used instead.

Check the WinSCP-specific to generate an WinSCP-specific URL. Note that you need to enable the option with the WebDAV protocol, if you want WinSCP to handle the URL, as WinSCP never registers for the http protocol.

Check the Save extension to include a save extension into the URL. As the extension is WinSCP-specific, the option WinSCP-specific should be selected along.

The generated URL(s) is shown in the bottom box. When generating an URL for a site, only one URL is displayed. When generating an URL for a selected file(s), one URL per a file is displayed.

Script Tab

Use the Script tab to generate a WinSCP script template for the session. This feature is available only in the latest beta release.

The script will include:

  • the open command with the session URL and all other switches needed to configure the session.
  • a placeholder text to be replaced with commands.
  • the exit command to end the script.

Advertisement

Use the Format to select a format of the script to generate:

  • Script file - Generates a script file template that you execute using the /script command-line switch.
  • Batch file - Generates a Windows batch file (.bat) template that executes the winscp.com with the above commands, specified using the /command command-line switch. Additionally the batch file enables session logging using the /log switch and isolates the script run from a GUI configuration using the /ini=nul switch. At the end, the batch file checks WinSCP exit code to choose further actions to take; and propagates the WinSCP exit code to a batch file exit code using the exit /b command.
  • Command-line - Generates a command-line for the winscp.exe (but usable for winscp.com too) with the above commands, session logging and configuration isolation (see the previous point). The command-line is suitable for task managers of all kinds, like Windows Scheduler or SSIS. Depending on your requirements, you may want prepend the /console switch to make the script console visible, while the script is running.

In the Command-line (and possibly also in the Batch file), you should modify a path to a session log file in the /log switch.

The script will not include options to verify the host key or certificate, if the session was not opened before yet. Open the session at least once, before generating the script.

You can click on script commands and switches and command-line switches to open their respective help pages.

.NET Assembly Tab

Use the .NET assembly tab to generate a code template using WinSCP .NET assembly for the session. This feature is available only in the latest beta release.

The code will:

  • Set up SessionOptions with all properties needed to configure the session.
  • Create Session instance.
  • Open the session using Session.Open
  • Include a placeholder text to be replaced with calls to Session methods.
  • Dispose the Session instance.

Use the Language to select a language to generate the template for. Available languages are C#, VB.NET and PowerShell.

The code will not set properties to verify a host key (SessionOptions.SshHostKeyFingerprint) or a certificate (SessionOptions.TlsHostCertificateFingerprint), if the session was not opened before yet. Open the session at least once, before generating the code.

Advertisement

You can click on classes, methods and properties to open their respective help pages.

Copying Generated URL or Code to Clipboard

Use Copy to Clipboard to copy generated URL(s) or code to a clipboard.

Last modified: by martin