---
title: "WinSCP Command-Line Simplified : Your Complete Reference"
description: "Explore the depths of WinSCP Command-Line in our guide. Master file transfer and automation with expert tips, techniques, and practical examples for users at all levels."
canonical: "https://adamtheautomator.com/winscp-command-line/"
---

# WinSCP Command-Line Simplified : Your Complete Reference

> Explore the depths of WinSCP Command-Line in our guide. Master file transfer and automation with expert tips, techniques, and practical examples for users at all levels.

Source: https://adamtheautomator.com/winscp-command-line/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![WinSCP Command-Line Simplified : Your Complete Reference](https://adamtheautomator.com/wp-content/uploads/2021/06/winSCP-command-line.jpg)

# WinSCP Command-Line Simplified : Your Complete Reference

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)28 November 202310 min. read

Categories: [IT Ops](/category/it-ops/)

Tags:[File Management](/tag/file-management/)[SSH](/tag/ssh/)

Table of Contents

*   [Prerequisites for Using the WinSCP Command Line](#h-prerequisites)
*   [Generating a Session URL with the WinSCP Command Line](#h-generating-a-session-url)
*   [Mastering the WinSCP Command-Line: Generating Session Connection Code](#h-generating-session-connection-code)
*   [Understanding WinSCP.exe vs. WinSCP.com in the WinSCP Command Line Context](#h-winscp-exe-vs-winscp-com)
*   [Utilizing WinSCP.exe: Connecting to Remote Hosts with Session URLs](#h-winscp-exe-connecting-to-remote-hosts-with-session-urls)
*   [Efficiently Downloading Files with WinSCP.exe Without a Site](#h-winscp-exe-downloading-files-without-a-site)
*   [Uploading Files Using WinSCP.exe Without a Site](#h-winscp-exe-uploading-files-without-a-site)
*   [Leveraging WinSCP.exe for Downloading Files Using a Site](#h-winscp-exe-downloading-files-using-a-site)
*   [Streamlining Remote File Editing with WinSCP.exe](#h-winscp-exe-editing-remote-files)
*   [Optimizing Workflow with WinSCP.exe Session Logging](#h-winscp-exe-session-logging)
*   [Exploring Advanced Features with WinSCP.com Interactive Commands](#h-winscp-com-running-commands-interactively)
*   [Enhancing Security: Connecting with a New Key Pair (Host Key) in WinSCP](#h-connecting-to-a-session-with-a-new-key-pair-host-key)
*   [Maximizing Efficiency with WinSCP.com: Using the /command Parameter](#h-winscp-com-running-commands-with-the-command-parameter)
*   [Automating Tasks with WinSCP.com: The /script Parameter](#h-winscp-com-running-scripts-with-the-script-parameter)
*   [Utilizing WinSCP.com for Key Conversion](#h-winscp-com-converting-keys)
*   [Conclusion](#h-conclusion)

WinSCP, a staple tool for secure file transfers, offers more than just a graphical user interface. The **WinSCP command-line** functionality allows IT professionals and sysadmins to manage and automate file transfers directly from the console, enhancing efficiency and flexibility in their workflow.

> _To learn the ins and outs of the WinSCP GUI, check out this post’s complementing post, [The WinSCP GUI: The Ultimate Guide](https://adamtheautomator.com/the-winscp-gui-the-ultimate-guide/)._

Discover every command-line feature WinSCP offers in this Ultimate Guide. You’ll learn, step-by-step, how to leverage the **WinSCP command line** to maximize your productivity and streamline your file transfer processes.

Let’s dive into the world of command-line file management with WinSCP!

## Prerequisites for Using the WinSCP Command Line

*   A Windows XP+ PC – This tutorial will use Windows 10 Enterprise.
*   A remote Linux host – This tutorial will use an [Ubuntu 18.04.5 LTS](https://releases.ubuntu.com/18.04/) machine.
*   A user account on the remote SSH host with sudo permissions.

## Generating a Session URL with the WinSCP Command Line

While the WinSCP GUI offers a convenient **Login** window for setting up connections, the **WinSCP command line** requires a different approach. Instead of interactive windows, you must specify connection attributes in a more direct manner.

![WinSCP command line: Connection attributes](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-5.png)

Connection attributes

To instruct the **WinSCP command line** on where to connect, a session URL is used. This URL encapsulates the connection attributes defined in the GUI.

A basic session URL follows this structure:

```powershell
<protocol>://<username>:<password>@<host name>/<folder path>
```

For example, to connect to the `1.1.1.1` host with username `adam` and password `pw` using SFTP in WinSCP, the session URL would be:

```powershell
sftp://adam:pw@1.1.1.1
```

If you’ve set up a WinSCP site, you can easily find the session URL. Open the WinSCP GUI, click on **Session**, right-click your site, and select **Generate Session URL/Code**.

![WinSCP command line: Generating a session URL](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-6.png)

WinSCP site

The Session URL dialog box provides various customization options for your connection, each influencing how WinSCP interacts with the remote host.

*   **Initial directory** – Specifies the remote directory that WinSCP opens upon connection.
*   **[SSH host key](https://winscp.net/eng/docs/session_url#hostkey)** – Uses an existing SSH key for remote host authentication.
*   **[WinSCP-specific URL](https://winscp.net/eng/docs/integration_url#winscp)** – Generates a unique session URL, like `WinSCP-sftp://`, specifically for WinSCP’s understanding, avoiding conflicts with default web browsers.
*   [Save extension](https://winscp.net/eng/docs/integration_url#save) – Often paired with WinSCP-specific URLs to further minimize application conflicts.

When all options are enabled, the session URL format should resemble the following:

```powershell
<protocol>://<username>:<password>@<host name>/<folder path><save extension>
```

![WinSCP command line: Generate Session URL/Code](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-8.png)

Generate Session URL/Code

## Mastering the WinSCP Command-Line: Generating Session Connection Code

With your session URL ready, WinSCP goes a step further by offering code examples in the **Generate session URL/code** window’s **Script** tab. Here, you can select from different script types:

*   Script file
*   Batch file
*   Command-line
*   PowerShell script

Choose your preferred script type, and WinSCP will generate the necessary syntax for connecting to a remote host using the **WinSCP command line**.

![WinSCP command line: Generating Session Connection Code](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-40.png)

Generating Session Connection Code

For coding in .NET, C#, or PowerShell, switch to the **.NET assembly code** tab, as depicted below.

![WinSCP command line: .NET assembly code tab](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-42.png)

.NET assembly code tab

## Understanding WinSCP.exe vs. WinSCP.com in the WinSCP Command Line Context

Knowing how to generate a session URL is crucial for using **WinSCP command line** tools. Let’s explore how to connect to a host using these tools, starting with understanding the differences between _winscp.exe_ and _[winscp.com](http://winscp.com)_.

_Winscp.exe_ doubles as the GUI launcher and a command-line utility for simple tasks. You can use it for basic commands if you specify the right parameters.

Think of _winscp.exe_ as a bridge between the GUI features and command-line interface of WinSCP.

For more complex tasks, especially in scripting, _[winscp.com](http://winscp.com)_ is your go-to. This console-based tool is ideal for automation scripts and supports a range of SSH functions. It provides a true, non-interactive **WinSCP command line** experience.

Regardless of your choice, begin by opening a command prompt (either _cmd.exe_ or PowerShell) and navigate to the WinSCP installation directory.

```powershell
cd 'C:\Program Files (x86)\WinSCP'
```

With the command prompt ready, let’s proceed to using WinSCP for remote connections.

## Utilizing WinSCP.exe: Connecting to Remote Hosts with Session URLs

One of the simplest methods to connect to a remote host with **WinSCP command line** is by running _winscp.exe_ with the session URL as a parameter. For instance, to connect to the `54.179.19.216` host with username `automate` and password `automate` using `sftp`, and then navigate to the _/tmp_ directory, use the following command:

```powershell
WinSCP.exe sftp://automate:automate@54.179.19.216/tmp/
```

For enhanced security, instead of using a password, you can connect to a remote host using a private key with the `/privatekey` parameter. While this method is more secure, the intricacies of setting up a private key fall beyond the scope of this tutorial on the **WinSCP command line**.

Related:[How to Create SSH keys](https://adamtheautomator.com/add-ssh-key-to-vs-code/)

Here’s an example of connecting to the `54.179.19.216` host using the username `automate` and a private key `mykey.ppk` over [`scp`](https://winscp.net/eng/docs/scp).

```bash
winscp.exe scp://automate@54.179.19.216/tmp/ /privatekey=mykey.ppk
```

## Efficiently Downloading Files with WinSCP.exe Without a Site

The **WinSCP command line** via _winscp.exe_ allows you to swiftly transfer files using ad-hoc connections, even without a predefined WinSCP site. Let’s explore downloading files from a remote host without a site configuration. For example, downloading all files in the _/tmp_ directory of the remote host 54.179.19.216 using SFTP.

1\. Start by generating a session URL. Below is an example connecting to the remote host with the credentials `automate` and landing in the _/tmp_ directory.

```powershell
# Generated Session URL
sftp://automate:automate@54.179.19.216/tmp
```

2\. Run _winscp.exe_ with the session URL to access the [WinSCP transfer settings dialog box](https://winscp.net/eng/docs/ui_transfer_custom). The local directory defaults to _~\\Documents_, and WinSCP will target all files (`\\*.*`) in the remote directory.

```powershell
# Command Syntax: winscp.exe [/path/[file]]
winscp.exe sftp://automate:automate@54.179.19.216/tmp
```

3\. Click OK to initiate the transfer. WinSCP will download all files from the remote _/tmp_ directory to your chosen local directory over SFTP.

![WinSCP command line: Downloading Files without a Site](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-43.png)

Downloading the Files without a Site

## Uploading Files Using WinSCP.exe Without a Site

After mastering file downloads, let’s switch to uploading files to a remote host using the **WinSCP command line** with _winscp.exe_. The process is similar to downloading, but this time you’ll also need to use the `/upload` switch, specifying the file or folder you wish to upload.

```powershell
# Uploading the file a.txt using winscp.exe to the remote server without a site.
.\WinSCP.exe sftp://automate:automate@54.179.19.216/tmp/ /upload C:\Users\shanky\Desktop\a.txt
```

Executing the command above brings up the WinSCP upload dialog, indicating the files to be uploaded (`*.*`) to the remote host’s _/tmp_ directory.

![WinSCP command line: Uploading Files without a Site](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-44.png)

Uploading the Files without a Site

After uploading, log into the remote host with an SSH client and verify the upload success with commands like `pwd` and `ls -lh`, which will display the directory contents, confirming the successful transfer.

![WinSCP command line: File Uploaded Successfully on Remote Machine](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-45.png)

File Uploaded Successfully on Remote Machine

## Leveraging WinSCP.exe for Downloading Files Using a Site

While session URLs are practical for ad-hoc connections, having a pre-configured WinSCP site simplifies the process. If you’ve been utilizing WinSCP for some time, you’re likely to have several sites already set up.

With _winscp.exe_, you can easily utilize these sites, created in the GUI, to connect to a remote host, bypassing the need to remember session URL details.

> _To locate saved sites in WinSCP, navigate to **Session** -> **Sites** -> **Site Manager**._

For instance, let’s explore downloading files using a pre-existing site with the **WinSCP command line**.

1\. Connect to the remote host using a configured WinSCP site. The example below demonstrates a connection using a site named `Adamsite`.

```bash
# Connect with a WinSCP site
winscp.exe Adamsite
```

Once connected, WinSCP displays a status notification.

![WinSCP command line: Connecting to Remote Machine Using a Site](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-46.png)

Connecting to Remote Machine Using a Site

2\. Next, execute _winscp.exe_ with the protocol (`sftp`), site name (`Adamsite`), and target directory (`/tmp`). This approach brings up the [WinSCP transfer settings dialog box](https://winscp.net/eng/docs/ui_transfer_custom), ready for file download actions.

```powershell
# Initiate remote connection using a site
winscp.exe sftp://Adamsite/tmp
```

Click OK to start downloading all files from the _/tmp_ directory of the remote host to your local directory via SFTP.

![WinSCP command line: Downloading Files Using a Site](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-47.png)

Downloading Files Using a Site

> _For uploading files from your local machine to a remote host, the process is analogous. Use the `/upload` switch along with the file or directory path, like `winscp.exe Site3 /upload .\license.txt`. Full URL specification (`sftp://Adamsite/tmp`) is not necessary._

## Streamlining Remote File Editing with WinSCP.exe

Need to edit a text file on a remote host? Skip the manual download-edit-upload cycle. The **WinSCP command line** offers a more efficient method using the `/edit` parameter. Simply specify the site name, `/edit`, and the remote file path.

Example:

```bash
# Editing a file on a remote host
winscp.exe /edit /Adamsite/path/to/file.txt
```

```powershell
# Using the WinSCP command line to edit a remote file
.\WinSCP.exe Adamsite /edit /tmp/a.txt
```

Executing the command above launches your default text editor, allowing you to modify the remote file as needed. This seamless integration is a key feature of the **WinSCP command line** capabilities.

![WinSCP command line: Editing Remote Files Using a Site](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-48.png)

Editing Remote Files Using a Site

After editing, simply save the file. WinSCP takes care of updating the file on the remote host, streamlining the edit-upload process.

## Optimizing Workflow with WinSCP.exe Session Logging

For a comprehensive record of your actions, the **WinSCP command line** offers session logging. This feature is invaluable for tracking the commands executed during a session, aiding in troubleshooting and record-keeping.

To enable session logging, include up to three parameters when connecting to a session:

```powershell
# Parameters for session logging
/log="<log file path>" /loglevel=<level> /logsize=<size>
```

*   `/log` – Specifies the path for the log file.
*   `/loglevel` – Sets the verbosity of the logs, ranging from _Reduced_ (`1`) to _Debug_ (`2`).
*   `/logsize` – Defines the size and rotation of the log file, in the format `<total archived logs>*<max log file size>`.

Below is an example of _winscp.exe_ connecting to a host and logging activity to `C:\winscp.log` at a _Debug_ level. The command maintains up to five 10MB log files (`5*10MB`).

```bash
# Example of WinSCP session logging
winscp.exe sftp://automate@54.179.19.216/tmp/ /log="C:\\winscp.log" /loglevel=2 /logsize=5*10M
```

## Exploring Advanced Features with WinSCP.com Interactive Commands

While _winscp.exe_ provides a great introduction to remote connections, _[winscp.com](http://winscp.com)_ elevates your command line experience, offering deeper interaction and control.

Begin by opening _[winscp.com](http://winscp.com)_ in a command line environment. You’ll enter an interactive session reminiscent of SSH, indicated by the `winscp>` prompt.

```bash
.\WinSCP.com
```

Connect to a remote computer using the `open` command, followed by the desired site name.

```bash
open Adamsite
```

After connecting to the remote host via **WinSCP command line**, as illustrated with `Adamsite`, you’ll find yourself in an environment akin to an SSH session. Here, you can execute commands and interact with the remote host efficiently.

![WinSCP command line: Interactively Running Commands using winscp.com](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-49.png)

Interactively Running Commands using winscp.com

### Enhancing Security: Connecting with a New Key Pair (Host Key) in WinSCP

Public-key authentication enhances security when connecting to sessions. To use it, first obtain the [host key fingerprint](https://winscp.net/eng/docs/faq_hostkey) for your session. Use the `ssh-keygen` command in the WinSCP folder following the syntax below.

This command generates an SSH key pair, essential for secure authentication. Once executed, you’ll receive a fingerprint necessary for _[winscp.com](http://winscp.com)_ session connections.

```bash
ssh-keygen -l -f /etc/ssh/ssh_host_rsa_key
```

![WinSCP command line: Verifying SSH Key Fingerprint](https://adamtheautomator.com/wp-content/uploads/2021/06/Untitled-50.png)

Verifying SSH Key Fingerprint

To connect with the `hostkey` parameter, provide the generated fingerprint as shown in the example below.

> _Include the prefix `ssh-rsa 2048` when using the fingerprint from `ssh-keygen`._

```bash
winscp.com open sftp://automate:automate@54.179.19.216/  -hostkey="ssh-rsa 2048 x4DeZzv4jcWEk2zeeJgr5JeJ+z0xA+lGa3LC0q/B+88="
```

## Maximizing Efficiency with WinSCP.com: Using the `/command` Parameter

While interactive sessions are great for certain tasks, non-interactive command execution is crucial for scripting and automation. _[winscp.com](http://winscp.com)_ supports this through the `/command` parameter, enabling you to establish a session, execute a command, and disconnect in a single step.

For example, use the `/command` parameter to transfer a local file to a remote host. The example below demonstrates copying a file from _C:\\abc\\abc.txt_ to the _/tmp_ directory on the remote host `13.213.61.127`.

The `/command` parameter takes two arguments as strings: one to establish the session and another for the actual command execution.

```powershell
# Non-interactive file transfer using WinSCP
WinSCP.com /command "open sftp://adam:adam@13.213.61.127/tmp" "put C:\\abc\\abc.txt"
```

```powershell
Session log for adam@13.213.61.127
C:\abc\abc.txt            |            0 B |    0.0 KB/s | binary |   0%
```

## Automating Tasks with WinSCP.com: The `/script` Parameter

For more complex automation needs, the `/script` parameter in _[winscp.com](http://winscp.com)_ allows you to execute a series of commands from a script. This feature is invaluable when managing repetitive tasks or complex operations on remote hosts.

To utilize the `/script` parameter in **WinSCP command line**, start by creating a script file named _upload\_file\_script.txt_ on your desktop with your preferred text editor.

Prepare a blank text file named _a.txt_ in the _/tmp_ directory of your remote computer.

Create a local directory at _C:\\abc_.

Next, input the following contents into _upload\_file\_script.txt_ and save it. This script downloads the _a.txt_ file from the remote _/tmp_ directory and re-uploads it as _new\_file.txt_.

```powershell
# WinSCP Script for File Transfer
 open sftp://automate:automate@54.179.19.216/  -hostkey="ssh-rsa 2048 x4DeZzv4jcWEk2zeeJgr5JeJ+z0xA+lGa3LC0q/B+88="
 cd /tmp
 get a.txt C:\abc\
 close
 open sftp://automate:automate@54.179.19.216/ -hostkey="ssh-rsa 2048 x4DeZzv4jcWEk2zeeJgr5JeJ+z0xA+lGa3LC0q/B+88="
 cd /tmp
 put C:\abc\new_file.txt 
 close
 exit
```

Execute this script using the `/script` parameter in WinSCP with the following command:

> _Use the `/ini=nul` switch to prevent WinSCP from saving any session configurations upon exit._

```bash
winscp.com /ini=nul /script=upload_file_script.txt
   # Output
   Authenticating...
   Session started.
   /tmp
   a.txt                     |           10 B |    0.0 KB/s | binary | 100%
   Session closed.
   # New session for upload
   Session started.
   /tmp
   C:\abc\new_file.txt       |            0 B |    0.0 KB/s | binary |   0%
   Session closed.
```

## Utilizing WinSCP.com for Key Conversion

WinSCP supports password and [certificate](https://adamtheautomator.com/x509-certificates/)\-based or public-key authentication. To use public-key authentication, a compatible private key format is required. WinSCP assists in converting key formats for compatibility.

Related:[Your Guide to X509 Certificates (For Mortals)](https://adamtheautomator.com/x509-certificates/)

For instance, convert a PEM format private key (like those from AWS EC2) to a Putty-friendly format using **WinSCP command line**. The `/keygen` parameter in _[winscp.com](http://winscp.com)_ facilitates this conversion.

*   Apply the `/keygen` parameter, followed by the key’s current path.
*   Include the `-o` parameter to specify the output file path of the converted key.
*   Optionally, use the `-c` parameter to add a comment to the converted key.

```powershell
.\WinSCP.com /keygen C:\Users\shanky\Desktop\testing.pem -o C:\Users\shanky\Desktop\testing.ppk -c "Converted from OpenSSH format"
```

## Conclusion

With this comprehensive guide to the **WinSCP command line**, alongside the [WinSCP GUI Guide](https://adamtheautomator.com/the-winscp-gui-the-ultimate-guide/), you’re now equipped to fully leverage WinSCP’s capabilities. Whether it’s file transfers, command execution, script running, or key conversions, WinSCP is a versatile tool for any IT professional.

How do you plan to integrate WinSCP into your workflow? Share your thoughts and experiences!

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fwinscp-command-line%2F&text=WinSCP%20Command-Line%20Simplified%20%3A%20Your%20Complete%20Reference)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fwinscp-command-line%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fwinscp-command-line%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2021/06/The-WinSCP-GUI-The-Ultimate-Guide.jpg)

### [The WinSCP GUI: The Ultimate Guide](/the-winscp-gui-the-ultimate-guide/)

New to WinSCP or want to learn a new trick? Check out this ultimate guide which walks you through all the features!

![](https://adamtheautomator.com/wp-content/uploads/2022/11/How-to-Install-NitroShare-for-Cross-Platform-File-Transfer.jpg)

### [Install NitroShare and Streamline Your File Transfers Today](/nitroshare/)

Simplify cross-platform file transfers with NitroShare. This tutorial guides you through installation and use for fast, effortless file sharing between different operating systems.

![](https://adamtheautomator.com/wp-content/uploads/2023/03/seafile.jpg)

### [Get Started With Seafile Self-Hosted Cloud Storage](/seafile/)

Get started with your own cloud storage solution. Seafile offers a self-hosted alternative with easy setup, secure file sharing, and data privacy.

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
