The WinSCP Command


The Best WordPress plugins!

1. WP Reset

2. WP 301 Redirects

3. WP Force SSL

Although the WinSCP command is not as well known as its counterparts, such as “Rename” and “Copy File/Folder,” it is often used to navigate your computer in a compact way. This guide will teach you how to use this powerful functionality of the program.

The “winscp command line example” is a command-line tool that allows users to transfer files from one computer to another. The tool can be used on Windows, Linux, and Mac computers. It can also be used with SSH protocol.

The WinSCP Command

WinSCP is a graphical tool for safe file transfer. However, it contains more functions than a GUI can display. You may also use the WinSCP command line to handle and automate file transfers from your terminal!

Check out the companion piece to this one, The WinSCP GUI: The Ultimate Guide, to learn more about the WinSCP GUI.

In this Ultimate Guide, you’ll discover how to use almost every Command-line tool WinSCP has to offer, step by step, so you can get more out of it.

Let’s get started!


  • A computer with Windows XP or later — The operating system used in this lesson is Windows 10 Enterprise.
  • A Linux host on the other side of the world — This lesson will be performed on a PC running Ubuntu 18.04.5 LTS.
  • A user account having sudo access on the remote SSH host.

Creating a URL for a Session

When using WinSCP in the GUI, you may use the Login window, which is seen below. You may provide remote connection characteristics in this window. The Command-line lacks such features as windows and interaction. You must instead specify those qualities in a different method.

Attributes of the connectionAttributes of the connection

To tell the WinSCP command line where to connect, you must provide a string called a session URL. This session URL is a combination of each of the Attributes of the connection you had defined in the GUI above.

At its most basic level, a session URL is defined by the schema:

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

For example, if you want to connect to the remote host with the user adam and the password pw using WinSCP and the SFTP protocol, your session URL would be:

If you’ve previously established a Site for WinSCP, open the WinSCP GUI, go to the Session menu, right-click on the site, and choose Create a URL/Code for the session.

Site for WinSCPSite for WinSCP

You may change the session URL in the Session URL dialog box above, which will determine how WinSCP connects to a remote host.

  • The remote directory that WinSCP will open when you connect for the first time.
  • SSH host key – An existing SSH key used to connect to a remote server.
  • WinSCP-specific – Generates a “WinSCP-specific” session URL such as WinSCP-sftp:// or winscp-<ftp://>. A WinSCP-specific URL is useful when you only need WinSCP to understand the URL. If you’d generate a session URL for FTP, for example, you’d be contending with your default web browser if you’d click the link.
  • Save extension – This option is often used in conjunction with the WinSCP-specific option to prevent other apps from conflicting with the URL when it is accessed.

With all settings enabled, the session URL should have the following syntax.

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

Create a URL/Code for the session. Create a URL/Code for the session.

Creating a Connection Code for a Session

WinSCP also gives code samples through the Script tab in the Generate session URL/code box after you’ve set the session URL. By choosing the appropriate code type:

  • file with the script
  • a batch document
  • Command-line
  • Script in PowerShell

In any of these script types, WinSCP will generate the syntax for connecting to the remote host using WinSCP.

Creating a Connection Code for a SessionCreating a Connection Code for a Session

Similarly, click on the.Tab for.NET assembly code to see the code for running WinSCP in.NET, C#, or PowerShell, as seen below.

Tab for.NET assembly codeTab for.NET assembly code

Now that you’ve learned how to create a session URL, it’s time to put it to use and learn how to connect to a host using WinSCP from the command line. But first, you must learn the differences between the two WinSCP CLI tools: winscp.exe and

Winscp.exe is the same program that launches the GUI, but it may also be used to do command-line functions. However, if you give a few options, you may use it on the command line to run some basic tasks.

Winscp.exe is only a command-line interface to the WinSCP GUI’s numerous functionalities.

Although winscp.exe is wonderful for quick, ad-hoc transfers on the command line, it won’t function in a script. In such scenario, is required. is a WinSCP-bundled software that only supports console operations and is ideal for automation scripts.

Many SSH capabilities are available via, which you may be acquainted with. is a genuine command-line experience that you’ll learn about later.

You must start a command prompt (either cmd.exe or PowerShell) and browse to the WinSCP installation path, regardless of the tool you use.

C:Program Files (x86)WinSCP cd

Let’s get started now that you’re in a command prompt!

WinSCP.exe: Using Session URLs to Connect to Remote Hosts

Running winscp.exe with the session URL as an argument is the easiest approach to connect to a remote host with WinSCP. In the example below, WinSCP connects to the server through sftp with the username automate and the password automate. It will be saved in the /tmp directory once connected.

You may connect to a remote host using a private key instead of a password by using the /privatekey argument. Using a private key instead of a basic password is more secure, but it is outside the scope of this article.

How to Create SSH Keys is a related topic.

An example of connecting to the server with a login and automating through scp with a private key named mykey.ppk can be found below.

Downloading Files Without a Site using WinSCP.exe

Using winscp.exe on the command line, you can transfer files using a quick, ad-hoc connection, or you can call upon a pre-created Site for WinSCP. Let’s first download a file without using a site. To demonstrate, perhaps you’d like to download all files in the remote host’s /tmp directory using SFTP.

1. Create a session URL first. The example below illustrates connecting to a remote computer using the automation username and password and dumping into the /tmp remote directory.

2. Next, open the graphical WinSCP transfer settings dialog box by running winscp.exe to connect to the remote host. You’ll see that the local directory is set to Documents by default, as shown below.

WinSCP will also use the *.* pattern, which means it will download all files with any name (*) and any file extension (*) by default.

# The command’s syntax is winscp.exe. [/path/[file]] sftp:/automate:[email protected]/tmp winscp.exe

3. To initiate the transfer, click OK. WinSCP will try to download all files from the distant /tmp directory to the local directory specified in the popup box through SFTP.

Obtaining the Files Without Using a WebsiteObtaining the Files Without Using a Website

Uploading Files Without a Site using WinSCP.exe

Now that you know how to download files from a remote host to a local workstation, try doing the converse and uploading data to a distant host.

Uploading files without a site using winscp.exe is similar to downloading files. Your session URL must still be provided. However, as demonstrated below, you must additionally use the /upload switch followed by the folder or file name.

# Using winscp.exe to upload the file a.txt to the remote server without specifying a site. sftp:/automate:[email protected]/tmp/ /upload WinSCP.exe C:UsersshankyDesktopa.txt

Following the winscp.exe command, WinSCP will display the graphical WinSCP upload dialog box, as shown below, showing that any files marked with /upload (*.*) will be uploaded to the remote host’s /tmp directory.

Uploading Files Without Using a WebsiteUploading Files Without Using a Website

You may verify that the file was successfully uploaded by logging onto the remote host with an SSH client and executing pwd to check the file andls -lh to display all files in the directory.

On the distant system, the file was successfully uploaded.On the distant system, the file was successfully uploaded.

WinSCP.exe: Using a Site to Download Files

In the previous examples, you had to specify a session URL. Session URLs are useful when you don’t have a Site for WinSCP to reference, containing all of the connection settings. If you’ve been using WinSCP for a while, chances are you have a few sites created.

You may utilize those sites generated using the GUI to connect to a remote host using winscp.exe, which saves you from having to remember how to build a session URL!

To find saved sites in WinSCP, click on the Session menu —> Sites —> Site Manager.

Let’s start with downloading files from a site to explain how to use sites using winscp.exe.

1. First, connect to the remote host defined in the site. The example below already has a Site for WinSCP created called Adamsite.

# winscp.exe Adamsite site|workspace|folder winscp.exe

After that, WinSCP will produce a status notice, as seen below.

Using a Site to connect to a distant computerUsing a Site to connect to a distant computer

2. Once connected, start a connection using winscp.exe, specifying just the protocol (sftp), site name (Adamsite), and remote directory (/tmp) this time.

With the folder to download the files to and the pattern (*.*) indicating all files in the directory, WinSCP will bring up the graphical WinSCP transfer options dialog box once again.

# Site winscp.exe sftp:/Adamsite/tmp sftp:/Adamsite/tmp sftp:/Adamsite/tmp sftp:/Adamsite/tmp sftp:/

Click OK, and WinSCP will use SFTP to download all files from the remote host’s /tmp directory to the local directory specified in the popup window.

Using a Website to Download Files Using a Website to Download Files

It’s comparable to uploading a file or a folder from your local system to a distant host. However, you must use the /upload switch together with the file or directory path to upload, for example, winscp.exe Site3 /upload.license.txt. It’s worth noting that the complete URL (sftp:/Adamsite/tmp) isn’t required.

Editing Remote Files using WinSCP.exe

You may want to maintain a text file on a remote host after you’ve created it, but you’ll need to change it. Instead of painstakingly downloading, modifying, and uploading a file using WinSCP, you may use the /edit parameter to perform everything in one go.

Provide the site name (Adamsite), the /edit argument, and the remote file path to edit to edit a file.

# Syntax: winscp.exe Site /edit <path> .WinSCP.exe Adamsite /edit /tmp/a.txt

Your default editor will appear when you run the above command, enabling you to modify the file as needed.

Using Site to Edit Remote FilesUsing Site to Edit Remote Files

Simply save the file when you’re done, and WinSCP will store it on the remote host!

Session Logging using WinSCP.exe

You may wish to keep track of the commands you’ve ran using winscp.exe. If that’s the case, WinSCP’s session logging feature is for you. WinSCP records command line input on a per-session basis, as configured when you connect to the session.

When connecting to a session, you may use up to three separate options to enable session logging, as illustrated below.

/log=”<log file path>” /loglevel=<level 1,2> /logsize=<size>

  • /log – The location to a local file where command history will be saved.
  • /loglevel — An optional argument that controls the level of logging verbosity. The log level is set to Normal by default. However, you may alter the logging level from Reduced or 1 to Debug or 2 for the most detailed logging.
  • /logsize – An optional parameter used to define how big the log file can get and how long until WinSCP rotates the log file. This parameter value is defined as <total archived logs>*<max log file in K, M, or GB>.

Here’s an example of what I’m talking about. In this case, winscp.exe will connect to the host and log all activity to the C:winscp.log file at the Debug level, with a total of five 10MB log files (5*10MB).

/log=”C:winscp.log” /loglevel=2* /logsize=5*10M winscp.exe sftp:/[email protected]/tmp/ /log=”C:winscp.log” /loglevel=2* /logsize=5*10M

Despite seeing a variety of methods to connect to a remote server and do a variety of tasks, you were doing it with training wheels on. You were utilizing the program winscp.exe.

WinSCP.exe is merely a tiny fraction of what the command line can genuinely achieve. It’s time you discovered if you actually want to learn about the command line.

Let’s start by utilizing and connecting to a remote computer, assuming you still have a command line and are still at C:Program Files (x86)WinSCP.

Run with no parameters, which will bring you into an interactive session similar to SSH. You’ll know you’re in a WinSCP session when the prompt changes to winscp>.

After that, use the open command to start a session and then the site you want to connect to.

In this scenario, you’ll see that WinSCP connects to the remote host specified in the site (Adamsite). You may issue commands and get output exactly as you would in a regular SSH session after you’ve joined.

Using to run commands interactivelyUsing to run commands interactively

Using a New Key Pair to Connect to a Session (Host Key)

If you want to connect to a session using public-key authentication, you must first locate the host key fingerprint for the session on your site. To do so, run the ssh-keygen command in the WinSCP folder using the syntax indicated below.

The ssh-keygen tool validates an SSH key pair that will be used to authenticate with the remote host. Execute the command as instructed below. You’ll see a fingerprint appear shortly, which you’ll need to present to in order to connect to a session.

/etc/ssh/ssh host rsa key ssh-keygen -l -f

The fingerprint is examined.The fingerprint is examined.

Once you have the fingerprint, use the open command to establish a session using the fingerprint you just produced as the hostkey parameter.

If you’re using ssh-keygen, always start the fingerprint with ssh-rsa 2048. /automate:[email protected] / -hostkey=”ssh-rsa 2048 x4DeZzv4jcWEk2zeeJgr5JeJ+z0xA+lGa3LC0q/B+88=” / -hostkey=”ssh-rsa 2048 x4DeZzv4jcWEk2zeeJgr5JeJ+z0xA+lGa3LC0q/B+88=”

You’ve already established an interactive session and used it to run commands while connected. You merely created one session and kept it active. Although this approach is quick, it does not enable you to execute scripts or other tasks that must be done without user interaction.

You must use the /command argument to run in “non-interactive” mode. You may use this argument to connect to a new session, perform a command, and then detach from that session all in one command.

Run the command below to transfer the local file C:abcabc.txt to the remote host’s ( /tmp directory to illustrate.

The /command parameter accepts two strings as arguments: the command to create the session (open sftp:/adam:[email protected]/tmp) and the command to execute in the session (put C:abcabc.txt).

# Using, copy the file abc.txt to the remote server’s tmp directory. “open sftp:/adam:[email protected]/tmp” “put C:abcabc.txt” /command

Looking for a place to stay… Trying to connect to the host… Authenticating… I’m using the username “adam.” Authenticating using a password that has already been typed. Authenticated. The session is about to begin… The session has begun. [1] [1] [1] [1] [1] [1] [ [email protected] C:abcabc.txt | 0 B | 0.0 KB/s | binary | 0 percent | C:abcabc.txt | 0 B | 0.0 KB/s | binary

When conducting ad-hoc management tasks, running single commands on distant systems is acceptable. Single commands, on the other hand, will not work if you’re attempting to automate a procedure in a remote connection. You’ll need to look at the /script parameter to do so.

1. To show the /script option, use your preferred text editor and create a text file on your desktop named upload file script.txt.

2. In your remote computer’s /tmp directory, create a blank text file named a.txt.

3. Make a directory on your computer. C:abc.

4. Save upload file script.txt with the contents shown below. You’ve just finished writing a WinSCP script!

In brief, the script below gets the a.txt file from the /tmp remote location and replaces it with new file.txt in /tmp.

# Open sftp to connect to a remote machine: /automate:[email protected] # Change remote directory cd /tmp -hostkey=”ssh-rsa 2048 x4DeZzv4jcWEk2zeeJgr5JeJ+z0xA+lGa3LC0q/B+88=” # Save the file to your computer’s local directory. get a.txt C:abc C:abc # Close the connection # Open sftp:/automate:[email protected] once again. # Change the remote directory cd /tmp -hostkey=”ssh-rsa 2048 x4DeZzv4jcWEk2zeeJgr5JeJ+z0xA+lGa3LC0q/B+88=” # Save the file as C:abcnew file.txt in your current working directory. # Close the connection # Shut down WinSCP.

5. Now, execute the file with the script with the following WinSCP command using the /script parameter providing the path to the script just created.

The /ini=nul argument instructs WinSCP to disregard the current site configuration and not preserve it when you depart.

> /ini=nul /script=upload_file_script.txt Searching for host… Connecting to host… Authenticating… Using username “automate”. Authenticating with pre-entered password. Authenticated. Starting the session… Session started. Active session: [1] [email protected] /tmp a.txt | 10 B | 0.0 KB/s | binary | 100% Session ‘[email protected]’ closed. No session. Searching for host… Connecting to host… Authenticating… Using username “automate”. Authenticating with pre-entered password. Authenticated. Starting the session… Session started. Active session: [1] [email protected] /tmp C:abcnew_file.txt | 0 B | 0.0 KB/s | binary | 0% Session ‘[email protected]’ closed. No session.

WinSCP may connect to a remote host using one of two methods: password or certificate-based authentication or public-key authentication, as you learned before. If you’re utilizing public-key authentication, you’ll need to provide a private key to Private keys, on the other hand, are not all created equal.

X509 Certificates: A Beginner’s Guide (For Mortals)

You’re trapped if you have a PEM-formatted private key created by the AWS EC2 service yet wish to utilize the popular SSH application Putty. However, WinSCP may assist you by converting keys for you. can convert keys to other formats for you if you use the /keygen argument. To do so, follow these steps:

  • To convert, use the /keygen argument followed by the key (PEM in this case).
  • Specify the -o argument and the location to the new key type’s output file.
  • Optionally, add a remark and use the -c argument.

/ -o UsersshankyDesktoptesting.pem C:UsersshankyDesktoptesting.pem ppk -c “Converted from OpenSSH format” C:UsersshankyDesktoptesting.ppk


WinSCP is a free program with a ton of capabilities. With this CLI tutorial and the WinSCP GUI guide, you should have a good idea of what this feature-rich program can do! WinSCP can accomplish a lot for you, including transferring files, performing commands, running scripts, and even converting key kinds.

What are your current plans for WinSCP?

The “winscp batch script” is a command-line tool that allows users to download and upload files to and from remote servers. The “winscp batch script” can also be used for other tasks like copying, renaming, deleting, moving, etc.

Frequently Asked Questions

How do I run a WinSCP command?

A: You can run a WinSCP command by typing it in the terminal on your computer. The syntax for this is as follows:/command

How do I use WinSCP?

A: WinSCP is a tool that allows you to browse files and folders on remote computers. You should enter the hostname or IP address of your computer in order to connect with it.

What is WinSCP and how does it work?

A: WinSCP is a file transfer client that allows you to access remote files using the SSH protocol. It can be installed on Windows, Linux, and Mac OS X.

Related Tags

  • winscp put command
  • winscp command line download
  • winscp get command
  • winscp script to download files from sftp
  • winscp command line copy file

Table of Content