How to scp from windows to windows

The `scp` command, which stands for secure copy protocol, is used in Windows Command Prompt to securely transfer files between a local and a remote host over SSH.

Here’s an example of the syntax for using `scp` to copy a file from your local machine to a remote server:

scp C:\path\to\local\file.txt username@remote_host:/path/to/remote/directory/

Setting Up SCP on Windows

Prerequisites

Installing OpenSSH on Windows
To use SCP in Windows CMD, you need to have OpenSSH installed. Follow these steps:

  1. Open Settings.
  2. Navigate to Apps > Optional features.
  3. Click on Add a feature.
  4. Search for OpenSSH Client and click on Install.
  5. Confirm the installation and wait for it to finish. Once installed, you’re ready to use SCP.

Ensuring SSH Client is Enabled

To confirm that the SSH Client is enabled:

  1. Open Control Panel.
  2. Go to Programs > Turn Windows features on or off.
  3. Check whether OpenSSH Client is listed and ticked. If not, check it and click OK to enable it.

Utilizing Windows CMD

Opening Command Prompt
To execute SCP commands, you need to access the Windows Command Prompt:

  • Press `Win + X` to open the quick access menu.
  • Select Windows Terminal (Admin) or Command Prompt (Admin) to ensure you have the necessary permissions for file transfers.

Mastering SSH in Windows Cmd: A Quick How-To Guide

Mastering SSH in Windows Cmd: A Quick How-To Guide

Understanding SCP Syntax

Basic Syntax Structure

The SCP command format is crucial for understanding how to use it effectively. The general syntax follows this structure:

scp [options] [source] [destination]

In this format:

  • [options]: Additional flags to modify behavior.
  • [source]: The file or directory you want to copy.
  • [destination]: Where you want to copy the file or directory to.

Breaking Down the Components

Options
Common options include:

  • `-r`: Use this flag to copy directories recursively.
  • `-P`: Specify a port when connecting to SSH.

Source
The source can be a local file (on your machine) or a remote file (on another machine) following the pattern `user@host:/path/to/file`.

Destination
Similar to the source, the destination can be a local path or a remote path, adapting the same user and host format.

Mastering Pwd in Windows Cmd: Your Quick Reference Guide

Mastering Pwd in Windows Cmd: Your Quick Reference Guide

Executing SCP Commands

Copying Files from Local to Remote

To transfer a file from your local machine to a remote host, you can use the following command:

scp C:\path\to\file.txt user@remote_host:/remote/path/

In this command:

  • `C:\path\to\file.txt` is your source file.
  • `user@remote_host:/remote/path/` specifies the user and host you’re transferring the file to.

Copying Files from Remote to Local

To copy a file from a remote server to your local machine, the command is slightly adjusted:

scp user@remote_host:/remote/path/file.txt C:\path\to\

Here:

  • The source is now the remote file, and the destination is your local path.

Copying Directories Recursively

If you need to transfer a directory and all its contents, include the `-r` option:

scp -r C:\path\to\folder user@remote_host:/remote/path/

This command ensures that not just the folder, but all its nested files and directories are copied.

Port Specification

If the SSH server is running on a non-standard port (not 22), you can specify this with the `-P` option:

scp -P port_number C:\path\to\file.txt user@remote_host:/remote/path/

Replace `port_number` with the actual port when connecting to the server.

Repair Windows Cmd: Quick Fixes and Tips

Repair Windows Cmd: Quick Fixes and Tips

Advanced SCP Usage

Using Identity Files

For added security, you may want to use SSH keys for authentication. If you have a private key, the command looks like this:

scp -i C:\path\to\key_file user@remote_host:/file/path /local/destination

This ensures that your key is used for connection without needing to input a password.

Batch Transfers

To copy multiple files matching a certain pattern, you can utilize wildcards:

scp C:\path\to\*.txt user@remote_host:/remote/path/

This command transfers all `.txt` files from your specified directory to the remote location.

Using Verbose Mode

If you encounter issues or want to see more information during the transfer, use the `-v` option:

scp -v C:\path\to\file.txt user@remote_host:/remote/path/

The verbose output will provide insights into the connection process and potential issues you may face.

Sleep Windows Cmd: Mastering Sleep Commands in Cmd

Sleep Windows Cmd: Mastering Sleep Commands in Cmd

Troubleshooting Common Issues

Authentication Errors

One of the most common problems is authentication errors. These typically occur due to incorrect username/password combinations or SSH key setups. Ensure that your credentials are accurate, and if using a key, ensure it is correctly referenced.

Connectivity Problems

If you experience connectivity issues, check your network connection. You can also use the `ping` command to verify the connectivity with the remote host.

Permissions Problems

Permission denied errors are common when your user does not have write access to the destination folder. Ensure you have the right permissions on the remote server to avoid this issue.

Lock Windows Cmd: A Quick Guide to Securing Your Commands

Lock Windows Cmd: A Quick Guide to Securing Your Commands

Conclusion

SCP in Windows CMD is a robust and versatile tool for transferring files securely between machines. With the proper setup and understanding of commands, it opens many possibilities for efficient file management across networks. By mastering these commands, you can enjoy streamlined file transfers while maintaining strong security protocols. With practice, you’ll find SCP is a vital addition to your toolkit for remote work.

Make File in Windows Cmd: A Quick Guide

Make File in Windows Cmd: A Quick Guide

Additional Resources

For those looking to deepen their understanding, consider browsing the official OpenSSH documentation or searching for tutorial videos that can guide you through various use-case scenarios.

В Windows 10 и Windows Server 2019 появился встроенный SSH клиент, который вы можете использовать для подключения к *Nix серверам, ESXi хостам и другим устройствам по защищенному протоколу, вместо Putty, MTPuTTY или других сторонних SSH клиентов. Встроенный SSH клиент Windows основан на порте OpenSSH и предустановлен в ОС, начиная с Windows 10 1809.

Содержание:

  • Установка клиента OpenSSH в Windows 10
  • Как использовать SSH клиенте в Windows 10?
  • SCP: копирование файлов из/в Windows через SSH

Установка клиента OpenSSH в Windows 10

Клиент OpenSSH входит в состав Features on Demand Windows 10 (как и RSAT). Клиент SSH установлен по умолчанию в Windows Server 2019 и Windows 10 1809 и более новых билдах.

Проверьте, что SSH клиент установлен:

Get-WindowsCapability -Online | ? Name -like 'OpenSSH.Client*'

'OpenSSH.Client установка в windows 10

В нашем примере клиент OpenSSH установлен (статус: State: Installed).

Если SSH клиент отсутствует (State: Not Present), его можно установить:

  • С помощью команды PowerShell:
    Add-WindowsCapability -Online -Name OpenSSH.Client*
  • С помощью DISM:
    dism /Online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0
  • Через Параметры -> Приложения -> Дополнительные возможности -> Добавить компонент. Найдите в списке Клиент OpenSSH и нажмите кнопку Установить.

клиент openssh установить компонент

]Бинарные файлы OpenSSH находятся в каталоге c:\windows\system32\OpenSSH\.

  • ssh.exe – это исполняемый файл клиента SSH;
  • scp.exe – утилита для копирования файлов в SSH сессии;
  • ssh-keygen.exe – утилита для генерации ключей аутентификации;
  • ssh-agent.exe – используется для управления ключами;
  • ssh-add.exe – добавление ключа в базу ssh-агента.

исполняемые файлы OpenSSH

Вы можете установить OpenSSH и в предыдущих версиях Windows – просто скачайте и установите Win32-OpenSSH с GitHub (есть пример в статье “Настройка SSH FTP в Windows”).

Как использовать SSH клиенте в Windows 10?

Чтобы запустить SSH клиент, запустите командную строку
PowerShell
или
cmd.exe
. Выведите доступные параметры и синтаксис утилиты ssh.exe, набрав команду:

ssh

usage: ssh [-46AaCfGgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
[-J [user@]host[:port]] [-L address] [-l login_name] [-m mac_spec]
[-O ctl_cmd] [-o option] [-p port] [-Q query_option] [-R address]
[-S ctl_path] [-W host:port] [-w local_tun[:remote_tun]]
destination [command]

параметры ssh клиента в windows

Для подключения к удаленному серверу по SSH используется команда:

ssh username@host

Если SSH сервер запущен на нестандартном порту, отличном от TCP/22, можно указать номер порта:

ssh username@host -p port

Например, чтобы подключиться к Linux хосту с IP адресом 192.168.1.202 под root, выполните:

ssh [email protected]

При первом подключении появится запрос на добавление ключа хоста в доверенные, наберите yes -> Enter (при этом отпечаток ключа хоста добавляется в файл C:\Users\username\.ssh\known_hosts).

Затем появится запрос пароля указанной учетной записи, укажите пароль root, после чего должна открытся консоль удаленного Linux сервера (в моем примере на удаленном сервере установлен CentOS 8).

подключение из windows 10 в linux с помощью встроенного ssh клиента

С помощью SSH вы можете подключаться не только к *Nix подобным ОС, но и к Windows. В одной из предыдущих статей мы показали, как настроить OpenSSH сервер на Windows 10 и подключиться к нему с другого компьютера Windows с помощью SSH клиента.

Если вы используете SSH аутентификацию по RSA ключам (см. пример с настройкой SSH аутентификации по ключам в Windows), вы можете указать путь к файлу с закрытым ключом в клиенте SSH так:

ssh [email protected] -i "C:\Users\username\.ssh\id_rsa"

Также вы можете добавить ваш закрытый ключ в SSH-Agent. Сначала нужно включить службу ssh-agent и настроить ее автозапуск:

set-service ssh-agent StartupType ‘Automatic’
Start-Service ssh-agent

Добавим ваш закрытый ключ в базу ssh-agent:

ssh-add "C:\Users\username\.ssh\id_rsa"

Теперь вы можете подключиться к серверу по SSH без указания пути к RSA ключу, он будет использоваться автоматически. Пароль для подключения не запрашивается (если только вы не защитили ваш RSA ключ отдельным паролем):

ssh [email protected]

Еще несколько полезных аргументов SSH:

  • -C
    – сжимать трафик между клиентом и сервером (полезно на медленных и нестабильных подключениях);
  • -v
    – вывод подробной информации обо всех действия клиента ssh;
  • -R
    /
    -L
    – можно использовать для проброса портов через SSH туннель.

SCP: копирование файлов из/в Windows через SSH

С помощью утилиты scp.exe, которая входит в состав пакета клиента SSH, вы можете скопировать файл с вашего компьютера на SSH сервер:

scp.exe "E:\ISO\CentOS-8.1.1911-x86_64.iso" [email protected]:/home

scp.exe копирование файлов через ssh

Можно рекурсивно скопировать все содержимое каталога:

scp -r E:\ISO\ [email protected]:/home

И наоборот, вы можете скопировать файл с удаленного сервера на ваш компьютер:

scp.exe [email protected]:/home/CentOS-8.1.1911-x86_64.iso e:\tmp

Если вы настроите аутентификацию по RSA ключам, то при копировании файлов не будет появляться запрос на ввод пароля для подключения к SSH серверу. Это удобно, когда вам нужно настроить автоматическое копирование файлов по расписанию.

Итак, теперь вы можете прямо из Windows 10 подключаться к SSH серверам, копировать файлы с помощью scp без установки сторонних приложений и утилит.

When you are working on the multiple servers, copying files between two servers is a common task for any system administrator. In this case, the SCP utility is the best choice for any system administrator.

SCP stands for “Secure Copy Protocol” is a Linux command-line tool used to transfer files and directories securely between two servers.

By default, GUI mode is not installed in Linux servers. SCP utility makes it easier for Linux system administrator to manage the multiple servers from the command-line.

SCP utility is based on the SSH, as so you will need a username and password of the source and target system to transfer the files.

In this tutorial, we will show you how to transfer files and directories between two systems using SCP file transfers!

Basic Syntax

The basic syntax of the scp command is shown below:

scp [OPTION] local-file-or-directory user@remote-ip:/directory/

You can use the above command to transfer files and directories from a local system to remote system.

scp [OPTION] user@remote-ip:/remote-file /local-directory

You can use the above command to transfer files and directories from a remote system to local system.

scp [OPTION] user@remote-ip:/directory/ user@remote-ip:/directory/

You can use the above command to transfer files and directories from one remote system to another remote system.

A brief explanation of each option in SCP command are shown below:

*Note: all these options are Case sensitive!

  • -r
    This option will copy files and directories recursively.
  • -v
    This option will display verbose output during the copying process.
  • -P
    This option is used to specify the ssh port number of the target host when the target host using the different SSH port.
  • -l
    This option is used to limit the bandwidth while copying the files and directories.
  • -q
    This option skips the SSH warning message.
  • -p
    This option will preserve permissions, modes and access time of files while copying.
  • -i
    This option is used to specify the SSH private key.

Transfer Files and Directories with SCP in Linux

The SCP utility allows you to transfer files between, local to remote, remote to local and remote to remote systems.

In this section we will show you how to transfer files and directories between them.

Local to Remote System Transfers:

Local to Remote File Transfers:

To transfer a file named file1.txt located inside /tmp directory from a local system to the remote system directory /opt use the following command:

scp /tmp/file1.txt root@172.20.10.3:/opt/

You will be asked to provide remote system’s root user password to transfer the file as shown below:

root@172.20.10.3's password:
file1.txt 100% 174KB 173.6KB/s 00:00

You can use the option -v with SCP to see the verbose output during the file transfer:

scp -v /tmp/file1.txt root@172.20.10.3:/opt/

Local to Remote Directories/Folders Transfers:

To transfer a directory named apt located inside /opt from a local system to the remote system directory /opt recursively use the following command:

scp -r /opt/apt root@172.20.10.3:/opt/

Provide remote system’s root user password to transfer the directory as shown below:

trustdb.gpg 100% 40 0.0KB/s 00:00
trusted.gpg~ 100% 22KB 21.7KB/s 00:00
mystic-mirage-pycharm-trusty.list 100% 146 0.1KB/s 00:00
ondrej-php.gpg 100% 364 0.4KB/s 00:00
minecraft-installer-peeps-minecraft-installer.gpg~ 100% 0 0.0KB/s 00:00
minecraft-installer-peeps-minecraft-installer.gpg 100% 378 0.4KB/s 00:00
projectatomic-ppa.gpg~ 100% 0 0.0KB/s 00:00
projectatomic-ppa.gpg 100% 1137 1.1KB/s 00:00
osmoma-audio-recorder.gpg 100% 353 0.3KB/s 00:00
nilarimogard-webupd8.gpg 100% 6541 6.4KB/s 00:00
webupd8team-java.gpg~ 100% 0 0.0KB/s 00:00
nilarimogard-webupd8.gpg~ 100% 0 0.0KB/s 00:00
mystic-mirage-pycharm.gpg 100% 366 0.4KB/s 00:00
webupd8team-java.gpg 100% 7140 7.0KB/s 00:00
osmoma-audio-recorder.gpg~ 100% 0 0.0KB/s 00:00
mystic-mirage-pycharm.gpg~ 100% 0 0.0KB/s 00:00
ondrej-php.gpg~ 100% 0 0.0KB/s 00:00
sources.list 100% 2951 2.9KB/s 00:00
sources.list.save 100% 2951 2.9KB/s 00:00
trusted.gpg 100% 23KB 23.2KB/s 00:00

Example:

Remote to Local Transferring:

Remote to Local File Transfers:

To transfer a file named hitesh.zip located inside /mnt directory of the remote to the local system’s directory /opt use the following command:

scp root@172.20.10.10:/mnt/hitesh.zip /opt/

You can increase the transfer speed by enabling the compression using the option -C with SCP as shown below:

scp -C root@172.20.10.10:/mnt/hitesh.zip /opt/

If your remote server uses SSH port 2022, then you can use -P option to specify the remote SSH port as shown below:

scp -P 2022 root@172.20.10.10:/mnt/hitesh.zip /opt/

Remote to Local Directory/Folders Transfers:

To transfer a directory named /etc from the remote system to local system’s directory /mnt recursively use the following command:

scp -r root@172.20.10.10:/database /mnt/

Example:

Remote to Remote System Transfers:

Remote to Remote File Transfers:

In order to transfer files and directories between two remote servers. You will need to configure SSH key-based authentication between both remote servers.

To transfer a file named /etc/rc.local from the one remote system (172.20.10.3) to another remote system’s (172.20.10.5) directory /opt use the following command:

scp root@172.20.10.3:/etc/rc.local root@172.20.10.5:/opt/

To transfer a directory named /mnt/apt from the one remote system (172.20.10.3) to another remote system’s (172.20.10.5) directory /opt use the following command:

scp -r root@172.20.10.3:/mnt/apt root@172.20.10.5:/opt/

Transfer Files and Directories with SCP in Windows (7, 8, 10, and Server)

If you are working on the Windows system and want to transfer files and directories from Windows to Linux and Linux to Windows system. Then, you can achieve this using WinSCP utility.

WinSCP is a free and open-source SCP and SFTP client for Windows based operating systems.

Transfer files between Windows and Linux system follow the below steps:

1. On the windows system, launch the WinSCP utility as shown below:

Now provide the following information:

  • File Protocol : Select SCP as file transfer protocol.
  • Host name : Provide your Linux server IP address.
  • Port number : Provide your Linux server SSH port.
  • User name : Provide the user name of your Linux server.
  • Password : Provide your user’s password.

2. Now click on the Login button. You should see the following page:

Click on the Yes button to verify the host. Once you are connected to the Linux server, you should see the following page:

On the left pane, right-click on the file you want to upload on the Linux server and click on the Upload button as shown below:

Now, provide the path of the Linux server’s directory and click on the OK button. Once the file has been uploaded, you should see the following page:

3. On the right pane, right-click on the directory you want to download from the Linux server to the Windows system and click on the Download button as shown below:

Now, provide the path of the Windows system directory and click on the OK button. Once the file has been uploaded, you should see the following page.

Conclusion

In the above tutorial, we’ve learned how to transfer files and directories from Linux to Linux, Windows to Linux and Linux to Windows. Feel free to ask questions below in the comments section if you have any!

Categories

  • Transfer Programs from C Drive to D Drive
  • Transfer Installed Software to New PC
  • Transfer Files from Old PC to New PC
  • Transfer Microsoft Office
  • Find Office Product Key
  • Move User Folder
  • Move Google Chrome Bookmarks

Relax and don’t worry if you are having trouble in transferring files between Windows Servers as the sample shown below:

How can I copy a file from one Windows server to another in a script? I have two Windows 2003 servers, and I want to write a backup script on one that will copy a file to the other. What’s the most idiomatic way to do this on Windows? — serverfault

Here on this page, we’ll present you with 3 reliable methods for accomplishing Windows Server file transfer tasks successfully. Feel free to share this page online to help more of your business partners:

How Do I Transfer Files from Windows Server to Windows Server?

Whenever you are working with multiple Windows servers, there comes a use case where you have to transfer files between them. But transferring files between servers is not as straightforward as you do with traditional copy-paste methods.

Therefore, you need other ways to copy files between Windows Servers. Below is the list of ways to help Windows Server users transfer files between Server computers in Windows Server 2022/2019/2016/2012 and more.

  1. Method 1. Windows Server Files Transfer Software
  2. Method 2. FTP Desktop
  3. Method 3. SCP Command Line

For the easiest and bulk file transfer solution, don’t miss Method 1 — Windows Server file transfer software — EaseUS Todo PCTrans Technician. It specializes in file transfer, folder transfer, and transfer of your other Windows Server assets.

EaseUS Todo PCTrans Technician Discount — Save Up to 40% Off

Safe and secure Windows Server file transfer software with the best price and immediate delivery. This is a time-limited offer.

Order with our specific COUPON CODE — EaseUSVIP

Method 1. Transfer Files from Windows Server to Windows Server Using File Transfer Software

For an efficient Windows Server file transfer resolution, the most feasible choice is to use automated file transfer software. They help you to transfer files between servers with easy steps. EaseUS Todo PCTrans Technician is professional automated file transfer software that can help you transfer files between Windows servers.

Apart from its extensive file transfer functionalities, it allows you to transfer files between server computers with and without a network. Follow the guide below to use this software to transfer files between Windows Servers.

Guide 1. Transfer Files from Windows Server to Server with Network

Step 1. Set Up the Old PC

  • First, install and launch EaseUS Todo PCTrans and select Data Transfer on the left panel of the main interface.

network transfer set on old pc

  • Select «Transfer Directly» and click «Next» to continue. 

select transfer directly

Step 2. Set Up the New PC

  • Download and launch EaseUS Todo PCTrans on the new computer; select «This is New PC» and click «Next».

network transfer on new pc

  • Select «Transfer directly» and click «Next» to continue. 
  • Select «Network» and click Next to continue. This will automatically scan the old PC. (Make sure the two PCs are connected to the same LAN.)

select network transfer

  • Select the target PC and click Connect. Then, it will take some time to scan and analyze the data in old PC.

connect two pcs

Step 3. Select the Files to Transfer

  • Finally, on the new PC, select the Files tab, select the files you need to transfer. Then, click «Transfer» to start.

select files

Guide 2. Execute Windows Server File Transfer without Network

Step 1. Create a backup file to transfer

  • Launch EaseUS Todo PCTrans on the source and target PCs. Click «Data Transfer» and select «This is Old PC». Then, click «Next» to continue.

Run EaseUS Todo PCTrans on old PC

  • Click «Transfer via backup» and select «Next» to continue.

select transfer mode as backup

  • Create a name for the backup of the files you wish to transfer without network. And click «Browse» to select the destination (a USB, external hard drive, or SD card) to save the backup of your target files. Then, click «Confirm».

Name the backup for files you want to transfer without network

  • Then, go to the Files tab, select the respective files you want to transfer to a new PC without network, and click «Back up».

Name the backup for files you want to transfer without network

After this, unplug the removable device with your file backup to the new computer.

Step 2. Restore and transfer backup files to the new PC without network

  • Launch EaseUS Todo PCTrans on the new computer, click «This is New PC» and click «Next».

Run EaseUS Todo PCTrans on new PC.

  • Select «Transfer via backup» and click «Next».

select transfer via backup to restore the file backup

  • Click «Browse» to select the file backup in your removable device. 

Select file backup to restore on the new PC

  • Click «Files» and select the backed up files you want to transfer from the old PC to your current new PC, and click «Restore». 

Restore file backup to new PC

In addition to sharing and transferring files, EaseUS Todo PCTrans Technician also works to transfer applications, data, computer settings, and even Windows Server accounts to another Server. Don’t forget to share this amazing tool online to help more of your business friends and set them free from file transferring on Windows severs:

Method 2. Transfer Files from Server to Server Using FTP

File Transfer Protocol (FTP) is how two computers on a network share files. In our case, FTP can help transfer files from Windows Server to Windows Server by creating an FTP connection.

Follow the below steps to create an FTP connection and then transfer files from Server to Server using FTP:

Step 1: On your computer, open File Explorer. Once opened, select This PC, right-click on the empty area, and select «Add a network location».

adding a network location

Step 2: A new window pop-up will appear. Select the «Choose a custom network location» button.

choosing a custom network location

Step 3: You need to enter the FTP server address on the next screen, which looks like ftp://server.com.

Once done, you need to enter the username and password for the FTP server. You can also choose the «Log on anonymously» for limited access.

adding the ftp server address

Step 4: Enter the name of your network location. The network location name will be used to set the network location link for your PC.

adding the name for the network location

Step 5: Transfer files by copy-pasting them inside the created FTP server folder.

transferring files through the ftp server

Method 3. Transfer Files Between Windows Server Computers Using SCP Command Line

SCP technique is based on SSH. SSH is Secure Shell, which gives an SSH key or password for authenticating the remote systems. You need to be careful with this method as it can overwrite files between two Windows Servers without warning for the file with the same name.

Follow the below steps:

Step 1: Press Windows + R simultaneously, type «cmd,» and press enter.

open cmd

Step 2: Open the command line and type related contexts according to your demand.

using scp command on windows server terminal

  • Transfer files from a Local Windows Server to a Remote Windows Server, type scp [OPTION] local-file-or-directory user@remote-ip:/directory/
  • Transfer files from a Remote Windows Server to a Local Windows Server, type scp [OPTION] user@remote-ip:/remote-file /local-directory/
  • Transfer files between two Remote Windows Server, type scp [OPTION] user@remote-ip:/directory/ user@remote-ip:/directory/

type command line to transfer between two remote systems

You need to replace the bracket arguments with your desired paths.

Understanding the SCP Command Arguments:

The general syntax for the SCP command is scp [OPTIONS] [SOURCE] [DESTINATION]. You can add the (@:) to add the server address.

  • [user]: You need to replace this argument with the username of your remote server.
  • [remote_host]: Enter your remote server address. It can be an IP address or domain name.
  • [file_path]: Your local file path.
  • [remote_file_path]: The path for the file on your remote server.
  • [local_dir]: Your directory on your local Windows Server.
  • [remote_dir]: The remote server directory path.

These are the three ways to transfer files from one Windows Server to another. If you think this guide is helpful, don’t forget to share it with others in need.

Which Is The Easiest Way to Transfer Files from Windows Server to Windows Server?

In the previous section, you have seen three methods for transferring files from Windows Server to Windows Server. However, the choice to choose the best method depends on various factors.

Comparison between three methods

The above three methods can be compared on factors such as price, transfer speed, and content you can transfer. See the below table to see a detailed comparison of the methods.

Server File Transfer Method Price Transfer speed Transfer content
EaseUS Todo PCTrans Technician File Transfer Software Free trial available but costs $399.0 per year Fast Files, applications, account settings, user files, system settings
FTP Connection Free Medium Files only
SCP Command Free Slow Files and applications

The comparison in the above table clearly states that EaseUS Todo PCTrans Technician is the most feasible and efficient way to transfer files between Windows Server computers.

Also, you get other key features with EaseUS Todo PCTrans Technician software. Let’s see each one of them below.

  1. 1. Application Migration: Transfer some applications between two Windows Server computers. 
  2. 2. Data Backup and Restore: Quickly back up your data. 
  3. 3. Data Rescue: Rescue your data from a broken or dead Server computer.
  4. 4. System Cleanup: Perform system cleanup on any local Windows Server computers.
  5. 5. Transfer User and Domain Accounts: Shift your accounts from one Windows Server computer to another with just one click.
  6. 6. Free Technical Support: Technical support comes free with the software. You can use their free assistance 24/7 anytime you need it through your phone or remote.

Learn more details from the section below:

EaseUS Todo PCTrans Enterprise

Batch computer program transfer, Windows account transfer, domain account transfer, virtual-physical machine transfer, local to cloud desktop transfer.

Technical Chat 24/7

Conclusion

The growing demand for data storage and manipulation has increased the need for multiple servers. Trendy server creation and usage are done through the Windows Server operating system. It helps to manage servers and create them easily.

With multiple servers, the use cases to transfer files between Windows Servers are a lot. However, the traditional copy-paste approach does not work when sharing files among Windows Severs. Therefore, you can use an FTP connection to share files among two Windows Servers. Also, the SCP command is another way to transfer the files among two Windows Servers.

However, the best file transfer method is using file transfer software, such as EaseUS Todo PCTrans Technician File Transfer Software. It allows you to transfer files, apps, accounts, etc., much faster with simple clicks.

SCP (Secure Copy) is a command-line utility that allows you to securely copy files from one computer to another over a secure, encrypted connection. It uses the SSH protocol to provide a secure connection to the remote system.

With the scp command you can securely copy files or directories in the following ways:

  1. From your local system to a remote system
  2. From a remote system to your local system
  3. Between two remote systems, while sending the commands from your local system.

The SCP command-line utility is available in most Linux distributions.

In this tutorial we’ll cover how to use the scp command in various scenarios to securely transfer files from one computer to another, using practical examples. We’ll also show you some of the most frequent options that you can use with the scp command to customize your file transfers.

SCP is usually used to refer to both SCP (the command-line utility, developed by the OpenSSH Project), as well as Secure Copy Protocol, which is the protocol used by the utility.

SCP is based on the Secure Shell (SSH) protocol, and it comes with a similar set of options, and is provided in most SSH implementations.

It uses credentials (such as passwords or SSH keys) for authentication, and it secures your transfers by encrypting both passwords and the transferred data, so your contents should be impervious to snooping.

A related protocol is SFTP (Secure File Transfer Protocol), however SCP does not have some of the capabilities that SFTP does, such as resuming broken transfers or remote file manipulation, like deletion.

SCP is similar to rsync, but unlike rsync, scp can only securely copy files and cannot sync directories.

Table of Contents
  1. About the SCP Command
  2. Before You Begin
    1. Requirements
    2. Useful Info
  3. SCP Command Syntax
  4. Securely Copy Files and Directories Between Two Hosts With the SCP Command
    1. 1. Copy a Local File to a Remote Host Using SCP Command
      1. Copy Multiple Local Files to a Remote Host
    2. 2. Copy a Remote File to Your Local Machine Using SCP Command
      1. Copy Multiple Remote Files to Your Local Machine
    3. 3. Copy a File between Two Remote Hosts Using the SCP Command
      1. Copy Files Between Two Remote Hosts That Are Not in The Same Network
    4. 5. Copy Files with Certain Extensions With the SCP Command
    5. 6. Copy a Directory Recursively With the SCP Command
  5. SCP Options
    1. SCP Verbose Mode (-v, -vv, -vvv)
    2. Transfer and Compress Files on The Fly (-C)
    3. Limit Bandwidth Usage (-l)
    4. Specify Port Number (-P)
    5. Set a Different Cipher (-c)
    6. Force SCP to Use IPv4 or IPv6 Addresses (-4 / -6)
    7. Automate File Transfers Using a SCP Shell Script
    8. SSH Key (Identity File) Path (-i) with the SCP Command
    9. Using Multiple SCP Command Options
    10. Preserve File Modification/Access Times and Modes With the SCP Command (-p)
    11. How to Resume Interrupted SCP File Transfers
      1. Resume Interrupted File Transfers with SFTP Reget or Reput
  6. Installing SCP (Optional)
    1. Install SCP on Linux
      1. Install SCP on Debian-based Distros
      2. Install SCP on RHEL-based Distros
    2. Install SCP on Windows
      1. pscp (Putty) – Windows SCP via Command-line
      2. Copy Files from Windows to Linux with PSCP
      3. Copy Files from Linux to Windows with PSCP
      4. WinSCP – GUI Version of SCP
  7. Conclusion

Before You Begin

Requirements

  1. To be able to transfer files from/to remote hosts via scp, you need the user’s authentication credentials – such as user/password or SSH keys.
  2. To be able to transfer files between systems you must have at least read permissions on the source file and write permissions on the destination system.

Useful Info

By default, scp operates on port 22 unless you change it using a command-line option.

You can use SCP with Linux, Mac, and Windows.
SCP should already be installed on Linux and Mac, however on Windows you have to install it – if you’re on Windows please see the section below on installing SCP on Windows.

When transferring large files, you’ll probably have to wait some time for the transfers to finish. For various reasons, you may not want to have to keep the command line open for hours. A solution here is running the scp command inside a terminal multiplexer such as screen or tmux, which allow you to leave commands running even if you log off.

SCP Command Syntax

The basic syntax of the SCP command is the following.

scp [OPTIONS] [[user@]SOURCE_HOST:]file1 [[user@]DESTINATION_HOST:]file2

Let’s break down and explain what the above expression means:

[OPTIONS]: Options alter the scp command’s behavior, such as changing the encryption cipher, ssh_config location, identity file location, limit bandwidth, change SSH port, recursive copy, and others.

You can check all available options by running man scp in the command line or read the scp man page online.

[[user@]SOURCE_HOST:]file1: This is the source file, the file to be copied.

If you’re copying from your local machine then you should just specify the relative (~/file1) or absolute path (/home/edxd/file1).

If the source file is located on a remote system, then you’ll have to specify the user and host (user@remote_source_ip) followed by the colon (:) separator, and then the file’s absolute or relative path.

For example: [email protected]:/var/www/file1.txt

[[user@]DESTINATION_HOST:]file2: This is the destination file, where the file is going to be copied.

If you’re copying to a remote host, it should include the user and host specification edxd@remote_destination_ip:/path/to/file2.

If you’re copying from a remote host to your machine, the absolute or relative path where you want the file copied, such as just /path/to/file2.

There are a few ways you can handle the remote user and host specifications.

You can use:

  1. an IP address: [email protected]
  2. a domain name: [email protected]
  3. a host defined in the /etc/hosts file
  4. a host defined in ~/.ssh/config (or %userprofile%\.ssh\config on Windows, usually C:\Users\your_user\.ssh\config)

Securely Copy Files and Directories Between Two Hosts With the SCP Command

1. Copy a Local File to a Remote Host Using SCP Command

It’s one of the most straightforward SCP commands you can carry out. We’re copying a single file (example.txt) from our computer to our remote host, which has .

To copy a local file to a remote host run a command like:

scp /path/to/example.txt [email protected]:/remote/path

Let’s quickly explain the above command.

/path/to/example.txt is the path to the file you want to copy from your local computer, remote_user is the user on the remote server, 121.134.21.14 is the IP of the remote host.

Next, comes a colon : after which you can specify the path where you want the file to be copied (/remote/path/). The copied file will retain it’s original name.

Here is a video to illustrate how this works. I’ll run the following command:

scp example.txt [email protected]:/home/stelixd

In the video below, on the left, we have a terminal on our local computer, and on the right we have the terminal of an Ubuntu remote server.

1. SCP Command — Copy a file from your local computer to a remote host

If you are connecting to your remote host for the first time, you will see the prompt Are you sure you want to continue connecting (Yes/no)?.

Assuming you trust the remote server, type Yes, press Enter, and fill in the user password (if you’re not using SSH keys).

When we execute the ls command on the remote server, you can see the example.txt was successfully copied.

You can also specify a new name for the file (/remote/path/file1_new_name):

scp /path/to/file1 [email protected]:/remote/path/file1_new_name

Copy Multiple Local Files to a Remote Host

You can also copy multiple files on our remote host in a single command. In my case I’ll transfer movie1.mp4, movie2.mp4, movie3.mp4, and movie4.mp4.

To transfer multiple files with the scp command just include all of them in the command, separated by a space:

scp movie1.mp4 movie2.mp4 movie3.mp4 movie4.mp4 [email protected]:/home/stelixd

2. Copy a Remote File to Your Local Machine Using SCP Command

To copy a remote file to your local machine using the scp command, just use the remote location as the source file, and the local location as the destination:

scp [email protected]:/home/stelixd/example.txt example.txt

Copy Multiple Remote Files to Your Local Machine

To copy multiple files from our remote host to our local machine, use the following syntax:

scp remote_username@remote_destination:/some/remote/directory/\{file1,file2,file 3\} /some/local/directory

Where remote_username@remote_destination is your remote host details, /some/remote/directory/ is a directory on your remote host, and \{file1,file2,file3\} are the files we want to transfer, separated by a comma, in escaped (\) curly braces {}.

Escaping is a method that allows us to tell a computer to do something special with the text we supply or to ignore the special function of a character. To tell the computer that it should expect an escape character we use a special escape marker, we usually make use of the backslash \, such as we have done with the curly braces (\{, \}).

Here is an example of me transferring 3 empty files from a remote server to a local computer:

scp mrtest:/home/edxd/\{file1,file2,file3\} /home/stelixd/

Output

file1 100% 5120KB 2.5MB/s 00:01
file2 100% 11MB 8.1MB/s 00:01
file3 100% 8192KB 8.0MB/s 00:00

3. Copy a File between Two Remote Hosts Using the SCP Command

With the scp command you can securely copy files from a remote host directly to another remote host, all without having to SSH into any of them.

You’ll just send the command from a third machine, such as your local computer. The following command will copy file1 between two remote machines:

scp user@remote_host_1:/var/www/file1 user@remote_host_2:/var/www/file2

Video Demo
Here is an example where I copy a file between two remote hosts with scp:

scp [email protected]:/home/edxd/my_file [email protected]:/home/stelixd

5. SCP Command — Copy Files Across Remote Hosts

Important: In some cases scp hangs, and doesn’t prompt you for both passwords so it can proceed with the transfer, and I’m not yet sure the reason for this.

One solution for this is setting up SSH-key based authentication between the computer issuing the command, and both the remote hosts.

Copy Files Between Two Remote Hosts That Are Not in The Same Network

Usually you can transfer files between remote machines with the scp command because they are on the same network, with routers between them that route the traffic.

But there are instances where you need to transfer files between remote machines that aren’t on the same network, because there are no routers between them, however you can connect to both of them from your computer.

With the scp command you have an option to transfer files through the third machine sending the command, such as your local computer. You can do this with the -3 option.

The following command will copy files from two machines through the machine that is sending the command.

scp -3 user@remote_host_1:/var/www/file1 user@remote_host_2:/var/www/file2

Video Demo

An example of the above command.

scp -3 [email protected]:/home/edxd/my_file [email protected]:/home/stelixd

5. SCP Command — Copy Files Across Remote Hosts (Route)

5. Copy Files with Certain Extensions With the SCP Command

To securely copy files of a specific type using the scp command you can run a command such as:

scp user@remote_host:'/directory/*.{html,php}' /destination/folder

Important Note: Please note the pair of single quotes ', along with the * wildcard, and curly braces with comma separated extensions. This will cause the shell to turn the expression into:

scp user@remote_host:/directory/*.html user@remote_host:/directory/*.php /destination/folder

6. Copy a Directory Recursively With the SCP Command

To copy a directory along with all its contents, we will include the -r (recursive) parameter in our SCP command. This command will copy a directory and all its contents:

scp -r transfer_folder user@remote_host:/remote/path/

Let’s copy the transfer_folder directory on our local computer to our remote host.

scp -r transfer_folder [email protected]:/home/stelixd

Video Demo

3. SCP Command — Copy a Directory Recursively

SCP Options

You can easily view the scp command’s options in your command-line by running man scp. We’ll explore a few of these options here.

SCP Verbose Mode (-v, -vv, -vvv)

By enabling verbose mode with the scp command, you can see debug information for SCP – essentially you’re seeing everything happening behind the scenes.

The more -v you use, the more verbose the output will be. The maximum number of -v is 3.

Video Demo

For our example we’ll copy a few files movie1.mp4, movie2.mp4, movie3.mp4 and movie4.mp4 using -v.

4. SCP Command — Copy Files Verbose Mode

Transfer and Compress Files on The Fly (-C)

If you are copying a large file or multiple files over a slow network, you can use the -C parameter, which will enable the scp command to compress the files before transferring them over the internet.

That may also save on your bandwidth if bandwidth is an issue. On reasonably fast connections, this might just slow things down, however.

Note: We have included the -v (verbose) parameter in the command below to see what is happening behind the scenes.

scp -vC example_file [email protected]:/home/stelixd

Video Demo

6. SCP Command — Compress and Copy Files

Limit Bandwidth Usage (-l)

When you’re copying a file from your local computer to a remote host, think of it as an upload process. Now, if the upload bandwidth used by the SCP command is high, it might impact the network or other processes and devices also uploading data.

Luckily, we can use the -l parameter and specify the bandwidth used by the SCP command in Kilobits/sec (kbps).

Important: Even though we specify the transfer rate in Kilobits/sec (kbps), the transfer rate will be displayed in Kilobytes/sec (KB/s). A Kilobyte is made up of 8 Kilobits. So when we specify, say scp -l 1600, we’re saying we want a transfer rate of 1600 Kilobits, which in KB/s means 1600 / 8 = 200 KB/s. As another example, if you want to limit transfer to 300 KB/s, you multiply 300 * 8 = 2400 Kilobits. So we run scp -l 2400.

In the command below, we will set our SCP transfer bandwidth to 800 Kb/s (800 * 8 = 6400 Kilobits/sec).

scp -l 6400 example_file [email protected]:/home/stelixd

7. SCP Command — Limit Bandwidth Usage

Specify Port Number (-P)

By default, SSH uses port 22.

For security reasons and other related measures, some people prefer changing this default port and configuring a custom port to work with the SSh service. You will need to specify the custom SSH port in your SCP command using the -P parameter in such a situation.

We haven’t configured any custom port in our case, and we will just enter port 22.

scp -P 22 example_file [email protected]:/home/stelixd

8. SCP Command — Specify Port Number

Set a Different Cipher (-c)

To securely copy files securely over a network, scp uses the AES encryption algorithm. To specify a different algorithm, use the -c parameter. For this example, we will use the aes128-ctr cipher. Some ciphers are more secure and others are faster than others.

Note: This -c parameter is a lowercase character, unlike our -C (uppercase) used for file compression.

scp -c aes128-ctr example_file [email protected]:/home/stelixd

9. SCP Command — Set a Different Cipher

Force SCP to Use IPv4 or IPv6 Addresses (-4 / -6)

You can specify whether the scp command should use IPv4 or IPv6, with the -4 and -6 options.

To use IPv4:

scp -4 /path/to/file1 user@remote_host:/remote/path/

To use IPv6:

scp -6 /path/to/file1 [email protected]:/remote/path/

Automate File Transfers Using a SCP Shell Script

If you have files or directories that you copy regularly, you can create a simple bash script and save the time of writing those long commands on the terminal.

There are various ways you can write scripts to use the SCP command.

In this example I’ll create a simple script that requests a target file or directory that I manually input, then it loops through some destinations in a file (that I’ve set beforehand), and transfers the file I entered to those destinations.

I created a file called destination_address.txt in the /tmp directory. This text file will hold the user@ip_address:/destination of our remote host. In this case, I want to transfer files to my remote server, in the ~/remote_transfers folder.

[email protected]:~/remote_transfers/

Now let’s create our bash script:

echo "=================="
echo "Running SCP Script"
echo "=================="
echo -e "Enter the path to the file you wish to copy:\c"
read file

for dest in cat /tmp/destination_address.txt; do
scp -r $file ${dest}

done

We will save our script as scp_script.sh. To make the script executable, remember to run the command chmod +x scp_script.sh.

To run it I’ll run:

sudo bash scp_script.sh

10. SCP Command — Automate File Transfers Using a SCP Shell Script

SSH Key (Identity File) Path (-i) with the SCP Command

If you have configured SSH key-based authentication, you can use the -i option and specify the path to the identity file.

Identity files come in different formats, depending on your setup and environment. For example .pub is the file format used by SSH, .pem can be used for AWS when you created your key-pair.

The following command connects to a remote host using an SSH Key.

scp -i /path/to/ssh_key.pub /path/to/local_file user@remote_host:path/to/remote/file

Using Multiple SCP Command Options

You can use multiple options in the same command. Some flags can be combined. If you check man scp you should see the scp command’s full syntax, which should give you a good idea on what flags you can combine:

scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file] [-J destination] [-l limit] [-o ssh_option] [-P port] [-S program] source ... target

Preserve File Modification/Access Times and Modes With the SCP Command (-p)

To preserve modification times, access times, and modes with the scp command you can use the -p flag:

scp -p /path/to/example.txt [email protected]:/remote/path

How to Resume Interrupted SCP File Transfers

The scp command does not understand range-request or partial transfer, such as HTTP does. As such, scp implementations, such as our command-line utility can’t resume interrupted downloads.

However, there are simple ways to resume interrupted scp transfers, by using other utilities that have this capability.

A very easy and straightforward way of resuming aborted downloads is using the sftp interactive commands reput and reget.

Resume Interrupted File Transfers with SFTP Reget or Reput

SFTP (SSH File Transfer Protocol) is a related secure transfer protocol, which is used to access, manage and transfer files using SSH.

To read more on sftp and its’ options you can run man sftp or read the sftp manual page online.

It works a little different than the scp command, as it offers an option to run interactive commands after connecting to a remote server.

The two interactive commands that can help us resume interrupted downloads or uploads are:
1. reget: resumes downloads
2. reput: resumes upload

In the following example we start downloading a 700 mebgabyte file called bytexd.txt from a remote server, that we interrupt by pressing Ctrl + C, when it’s at 9%:

scp user@remote_host:/remote/directory/bytexd.txt bytexd.txt

Output

bytexd.txt 9% 65MB 3.1MB/s 03:34 ETA

To continue the download we’ll have to connect to the remote host using sftp:

sftp user@remote_host

You will have to authenticate, such as you would with scp or ssh.

When you’re logged in with sftp you’ll notice your prompt has changed into:

sftp>

Now we can run interactive commands.

You can also run commands such as cd and ls to navigate and find your files. Read more on all available interactive commands in the man page.

To resume the download, we’ll run the reget interactive command, followed by the file path on the remote directory:

sftp> reget /remote/directory/bytexd.com

Output

Resuming /remote/directory/bytexd.txt to bytexd.txt
/remote/directory/bytexd.txt 10% 73MB 771.1KB/s 13:53 ETA

Installing SCP (Optional)

On Linux and Mac, scp is usually already installed, and on Windows you’ll most likely have to install it yourself.

Install SCP on Linux

Installing scp will different, depending on your distro.

Install SCP on Debian-based Distros

To install scp on Debian-based distros (such as Debian, Ubuntu, Linux Mint, and others) run:

sudo apt install openssh-client

Install SCP on RHEL-based Distros

To install scp on RHEL-based distros (such as CentOS, Fedora, Rocky Linux, AlmaLinux, and others) run:

sudo dnf install openssh-clients

Install SCP on Windows

The scp command doesn’t come installed on Windows so we’ll have to install it ourselves. We’ll cover two common ways. There are probably more out there, but these two are popular and tested.

pscp (Putty) – Windows SCP via Command-line

PSCP (PuTTY Secure Copy) is similar to scp and comes bundled with PuTTY, probably the most used SSH client for Windows. It is free and open-source.

You can download and install Putty from the developer’s (Simon Tatham) website, if you don’t have it already.

You can also download and install pscp.exe separately, if you prefer.

After installing it, open a new command shell (like cmd.exe) and run:

pscp

You should see something like:

PuTTY Secure Copy client
Release 0.74
Usage: pscp [options] [user@]host:source target
       pscp [options] source [source...] [user@]host:target
       pscp [options] -ls [user@]host:filespec
Options:
  -V        print version information and exit
  -pgpfp    print PGP key fingerprints and exit
  -p        preserve file attributes
  -q        quiet, don't show statistics
  -r        copy directories recursively
  -v        show verbose messages
  -load sessname  Load settings from saved session
  -P port   connect to specified port
  -l user   connect with specified username
  -pw passw login with specified password
  -1 -2     force use of particular SSH protocol version
  -4 -6     force use of IPv4 or IPv6
  -C        enable compression
  -i key    private key file for user authentication
  -noagent  disable use of Pageant
  -agent    enable use of Pageant
  -hostkey aa:bb:cc:...
            manually specify a host key (may be repeated)
  -batch    disable all interactive prompts
  -no-sanitise-stderr  don't strip control chars from standard error
  -proxycmd command
            use 'command' as local proxy
  -unsafe   allow server-side wildcards (DANGEROUS)
  -sftp     force use of SFTP protocol
  -scp      force use of SCP protocol
  -sshlog file
  -sshrawlog file
            log protocol details to a file

File path notation is different for Windows that for Linux. With pscp you must specify the file paths appropriately for each operating system.

Copy Files from Windows to Linux with PSCP

To copy files from Windows to Linux, using pscp you can run something like:

pscp c:\path\to\file user@destination_host:/path/to/file

Copy Files from Linux to Windows with PSCP

To copy files from Linux to Windows using pscp:

pscp user@destination_host:/path/to/file c:\path\to\file

WinSCP – GUI Version of SCP

WinSCP is a very popular GUI (graphical user interface) software, for Windows, that allows copying files between local and remote hosts, and supports the following file transfer protocols – SCP, FTP, FTPS, SFTP, WebDAV and S3.

It’s very straightforward and easy to use. To install it follow the instructions in the install guide , and you can read about its features and other useful information in the Documentation.

Many Windows users prefer WinSCP since it mainly offers a graphical user interface and offers functionalities such as:

  1. Drag & Drop: Simply using the interface to drag/drop files to copy them from the local to the remote system, and vice versa.
  2. Synchronizing: Which synchronizes content of a local directory onto the remote directory, vice versa, or even full sync which means that any modification made on either system, it will be applied to the other system.
  3. Resuming Transfers
  4. .. many more that you can find in the WinSCP Docs

Conclusion

This post has given you a detailed guide on using the scp command to transfer files securely, and how to use some of the most common options. To easily see all the scp command options, along with their explanations, you can run the man scp command in your command-line, or you can read them online.

If you have any questions or requests, then feel free to let us know in the comments section and we’ll get back to you as soon as we can.

Понравилась статья? Поделить с друзьями:
0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии
  • Настройка значений по умолчанию для цветовой системы windows wcs
  • Как закрыть программу task host windows
  • Как изменить директорию в командной строке windows
  • Терминальный сервер из windows 10 termsrv dll
  • Можно ли удалить папку windows media player