Scp from linux to windows примеры

ИТ База знаний

Курс по Asterisk

Полезно

— Узнать IP — адрес компьютера в интернете

— Онлайн генератор устойчивых паролей

— Онлайн калькулятор подсетей

— Калькулятор инсталляции IP — АТС Asterisk

— Руководство администратора FreePBX на русском языке

— Руководство администратора Cisco UCM/CME на русском языке

— Руководство администратора по Linux/Unix

Серверные решения

Телефония

FreePBX и Asterisk

Настройка программных телефонов

Корпоративные сети

Протоколы и стандарты

Популярное и похожее

Курс по сетям

15 примеров команды PING для диагностики сети

Руководство по команде grep в Linux

Рекурсивно найти слово в файлах и папках Linux

Права доступа к MySQL через Linux

Руководство по команде grep в Linux

Как создавать и выбирать базы данных MySQL в Linux

10 команд Linux, которые убьют ваш сервер

Еженедельный дайджест

Команда SCP Linux: безопасное копирование и передача файлов

4 минуты чтения

Команда SCP (Secure Copy) — это метод шифрования передачи файлов между системами Unix или Linux. Это более безопасный вариант команды cp

Обучайся в Merion Academy

Пройди курс по сетевым технологиям

Начать

SCP включает шифрование через соединение SSH (Secure Shell). Это гарантирует, что даже если данные будут перехвачены, они будут защищены.

Как безопасно копировать файлы с помощью SCP

Копировать файл с локального на удаленный сервер с помощью SCP

Команда scp позволяет использовать подстановочные знаки.

Используйте символ тильды

/ для обозначения home/user каталога пользователя.

Вы можете указать строку текста со знаком * .

/*.txt заставит SCP скопировать все файлы в домашнем каталоге, которые заканчиваются на .txt .

Как правило, вам не нужно указывать расположение файла в текущем каталоге. Если вы находитесь в каталоге /home/user и хотите скопировать файл test.txt на сервер, вы можете ввести следующее:

Чтобы скопировать все файлы .txt в домашний каталог username2 , введите следующее:

Если вы укажете только каталог назначения, SCP оставит имя файла как есть.

Чтобы изменить имя файла, определите новое имя файла в месте назначения:

В этом примере файл test.txt копируется с локального компьютера, а затем сохраняется как user1test.txt в каталоге пользователя системы назначения.

Если удаленная система настроена на прослушивание SSH-запросов на порт, отличный от порта 22 по умолчанию, используйте переключатель –P , чтобы указать порт:

Это копирует test.tx t из вашей локальной системы на целевой хост, используя порт 1234.

Копировать с одного удаленного хоста на другой

Вы не ограничены только подключением между локальным компьютером и удаленным сервером.

Чтобы скопировать из одной удаленной системы в другую:

Это приведет к репликации файла test.txt из каталога /files на host1.com в каталог /files на /host2.com. Система предложит вам ввести пароль для пользователей user1 и user2 до завершения операции.

Копирование больших файлов с помощью SCP

Если вы копируете большие файлы, запустите команду в терминальном мультиплексоре, например tmux .

Если операция прервана, мультиплексор позволит вам возобновить копирование без необходимости начинать заново.

Вы можете проверить, установлен ли в вашей системе tmux , выполнив в терминале следующее:

Рекомендации по использованию SCP

Команда scp не проверяет место назначения перед записью. Любые файлы в месте назначения с тем же именем будут перезаписаны без уведомления.

Вам будет предложено ввести пароль, когда вы нажмете Enter.

Используйте пароль пользователя в удаленной системе.

Управление разрешениями

В исходной системе вам потребуется учетная запись с доступом для чтения к файлам, которые вы хотите скопировать.

В системе назначения вам потребуется учетная запись с правом записи в каталог, в котором будут сохранены файлы. Если вы столкнетесь с ошибками при копировании, вы можете попробовать учетную запись пользователя root для устранения неполадок с разрешениями.

Параметры команды SCP

Базовый синтаксис SCP:

Вот некоторые общие параметры команды scp:

  • –P — Указать порт SSH сервера
  • –p — сохранить метку времени для изменения и доступа (обратите внимание на строчные буквы)
  • –q — тихий режим, без отображения прогресса или сообщений (все равно будут отображаться ошибки)
  • –C — Сжимать данные во время передачи
  • –r — Рекурсивно — включать подкаталоги и их содержимое

Раздел, следующий сразу за параметрами, — это источник (путь) файла, который вы хотите скопировать. Вы можете скопировать из своей системы в удаленную или наоборот.

Читайте также:  Вебсервер для windows это

В следующем разделе указывается место, куда копируется файл. Например:

Это скопирует документ test.txt из пользовательского каталога в локальной системе и поместит копию в каталог учетной записи администратора в удаленной системе.

Другой пример SCP — чтобы скопировать файл с удаленного хоста на локальный:

Итоги

В этом руководстве вы узнали, что такое команда scp и как ее использовать для защиты передачи файлов.

Как подключить SCP с сервера Linux к клиенту Windows

Я SSHing на Linux-машину, используя PuTTY и пытаюсь скопировать файл куда-нибудь (где угодно) на мою локальную машину. Я понять SCP является лучшим кандидатом на работу , но на самом деле не волнует, так долго , как решение работает!

Я cd в каталог, содержащий файл, который я хочу ( app.war ) и введите следующее:

Я пробовал оба безрезультатно:

Это заставило меня задуматься о том, что, возможно, SCP является клиент-серверным инструментом и требует клиента на моей машине с Windows, которого там нет.

Я просто использую неправильный синтаксис? Или я далеко от базы? Если да, какие варианты у меня есть? Заранее спасибо!

чтобы вы могли копировать файлы обратно в Windows, вам нужен SSH-демон / служба, работающий в Windows, вместо этого гораздо проще использовать этот инструмент, у него есть возможность импортировать сессии из Putty, очень простого клиента любить это!

Ты прав. SSHD — это службы сервера SSH, которые работают на хосте. Он принимает соединения от клиентов SSH (например, PuTTy), клиентов SCP и клиентов SFTP.

Вы можете скачать pscp с того же сайта, где размещается PuTTY .

На компьютере с Windows вы должны выполнить команду, аналогичную

pscp.exe someuser@somehost.com:/path/to/app.war c:\tmp

Для SCP-файла на компьютер с Windows вам необходим сервер SSH / SCP в Windows.

По умолчанию в Windows нет поддержки SSH / SCP. Вы можете установить сборку Microsoft OpenSSH для Windows ( Релизы и Загрузки ). Он доступен в качестве дополнительной функции в Windows 10 версии 1803 и новее. Он также может быть установлен вручную в старых версиях Windows.

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

Если у вас есть SSH-доступ из Windows в Linux, у вас также есть SCP-доступ (или даже лучше SFTP-доступ).

Используйте любой доступный клиент SCP / SFTP.

Другой альтернативой является набор инструментов PuTTY, который включает pscp инструмент командной строки с синтаксисом, похожим на команду OpenSSH scp . Кроме того, последние версии Windows 10 поставляются со scp встроенным OpenSSH и могут быть установлены на более старые версии.

Scp from linux to windows примеры

Contents

Introduction

scp stands for secure cp (copy), which means you can copy files across ssh connection. That connection will be securely encrypted, it is a very secure way to copy files between computers.

scp uses by default the port 22, and connect via an encrypted connection or secure shell connection. (ssh for short)

You can use scp command in these scenarios:

  • Securely copy files from remote computers to your computer
  • Securely copy files from your computer to remote compueters
  • Securely copy files from one remote computer to another remote computer

In the last case the traffic goes directly from one server to the other without passing through your system, that is a good thing if you have a slow Internet connection

You can use scp on Linux, Mac and Windows (using WinSCP). You may also want to check sftp

We will learn in this tutorial about the basic use of the command, and some useful examples and scenarios where you can use it.

Syntax

Explaining the complete syntax and every option of scp command is out of the scopy of this page, you can always enter a the command prompt

Or you can read it online here

We are going to explain the basic part of it:

scp Is the command itself and tells the operating system to copy one or more files over a secure shell connection, better known as ssh connection. [[user@]host1:]file1 The origin, where you specify the file or files to be copied, it can contain or not the information about a remote host, and it can also contain the information about the user owning the file or files in that remote host. If the user is not specified it will defaults to the current user in the machine where you are typing the command. If the host is not specified, it will look for the file locally using any given path. [[user@]host2:]file2 The destination, where you specify the path where the files are going to be copied, once again, it can contain or not the information about the remote host and/or user in that host. Same as above if the user is not specified but a hostname is given it will defaults to the current username and will try to log in the remote server using that user. And in the same way as with origin, if the host is not specified, the files will be copied locally.

Читайте также:  Windows app store free apps

Just to clarify, you can avoid specifying both username and host in origin and destination, and the scp command will work just like the cp command, copying a local file to a local destination.

Examples

Copy one single local file to a remote destination

So, if you wan to copy the file /home/user/table.csv to a remote host named host.example.com and copy there to jane’s home folder, use this command.

Copy one single file from a remote server to your current local server

Let’s say now you want to copy the same file from jane’s home folder in host.example.com to your local home folder.

Copy one single file from a remote server to another remote server

With scp you can copy files between remote servers from a third server without the need to ssh into any of them, all weight lifting will be done by scp itself.

Let’s say now you want to copy the same table file from jane’s home folder to pete’s home folder in another remote machine.

Copy files between two remote server that are not in the same network

In the example above host and host2 can route traffic between them, either because they are on the same network or because there are routers in between that route the traffic. But in the case that they are in two different networks with no routers in between you will need to route traffic through the server issuing the command. This would be the scenario.

The command you will need is:

You need to issue the command in Host 0 and it has to have connection with the other two hosts

Copy one single file from a remote host to the same remote host in another location

This time, you will be copying from one host to the same host, but on different folders under the control of different users.

Copy multiple files with one command

You can copy multiple files at once without having to copy all the files in a folder, or copy multiple files from different folders putting them in a space separated list.

If the files are in different folders, just specify the complete path.

Copy all files of a specific type

This will copy all files of a given extension to the remote server. For instance, you want to copy all your text files (txt extension) to a new folder.

You can make use of wildcards in any way you want.

Copy all files in a folder to a remote server

This will copy all files inside local folder to the remote folder, let’s see an example.

All files in local folder html, will be copied to backup folder in host.example.com

Copy all files in a folder recursively to a remote server

Same as the previous example, but this time it will copy all contentes recursively

Copy a folder and all its contents to a remote server

This time the folder itself is copied with all its contents and not only the contents. One more time we’ll use an example.

This will result in having in the remote server this: /home/jane/backup/html/. The whole html folder and its contentes recursively have been copied to the remote server.

We have seen the basic uses scp, now we will see some special uses and tricks of this great command

Increase Speed

scp uses AES-128 to encrypt data, this is very secure, but also a litle bit slow. If you need more speed and still have security, you can use Blowfish or RC4.

To increase scp speed change chipher from the default AES-128 to Blowfish

Or use RC4 which seems to be the fastest

This last one is not very secure, and it may not be used if security is really an issue for you.

Increase Security

If security is what you want, you can increase it, you will lose some speed though.

Limit Bandwidth

You may limit the bandwidth used by scp command

Where limit is specified in Kbit/s. So for example, if you want to limit speed at 50 Kbps

Save Bandwidth

Yoy can save bandwidth by enabling compression, let’s see our example with compression.

Use IPv4 or IPv6

If you want to force the use of either IPv4 or IPv6 use any of these ones.

The above one is for IPv4, and below for IPv6.

Читайте также:  Как настроить windows outlook 2010

Specify a port

If the remote server does not have ssh listening on default 22 port, you can make scp to use the port where the remote server is listening to:

Using the capital letter P you can make scp to use a port other than 22 which is the default for ssh. Let’s say your remote server is listening on 2222.

Use verbose output

If you want to see what is happening under the hood, use the -v parameter for a verbose output

Move instead of copy files from one server to another

This is a question that was asked on server fault, and as it clarifies in that page, the best option is rsync, but if you can’t use it here is a way to copy files with scp, and then if the copy was successful, you can delete the files from the origin.

This only works if you have configured your Linux ssh server to work with ssh-key instead of password

Copy files recursively preserving file attributes

If you want to copy a complete directory recursively and preserving file attibutes use this command:

-r copy directories recursively -p preserve file attributes

Windows

If you are working on a Windows powered computer, you can still enjoy scp in various ways, of course if you are a «*nix guy» you will prefer the command line, and you also have GUI tools available.

pscp is a shell command that works almost on Windows Shell almost the same way that scp works on Linux or Mac OS X, you first need to download it from this page, here is the direct link.

Once downloaded you can invoque it from the Windows command line, go to the start menu and click on run then write

And press ENTER, if you are on Windows 8.x hit the Windows/Super key and click on the magnifier lens, type cmd and hit ENTER.

Once in the command line, be sure to be in the directory where the pscp file was downloaded, or add that folder to your PATH, let’s suppose the folder is your Downloads folder, run this command:

You will have to set that command every time you open a new command shell, or you can add the path permanently, how to do that is out of the scope of this article.

Below are the options of the command, you will see that the options available let you do almost everything.

Copy files from Windows to Linux

You can use scp command to copy files from Linux to Windows

Copy files from Linux to Windows

You can also copy files from Windows to Linux, using pscp from the Windows computer you can «push» the files to the Linux, Max OS X or *BSD server.

Specify protocol

You can specify the protocol that scp command for Windows will use at the time of connection.

-scp This will force pscp to use scp protocol -sftp This will force pscp to use sftp protocol, which is a newer protocol than scp protocol

WinSCP

WinSCP is a GUI version of scp, mainly for Windows, its development was started on 2.000 by Martin Přikryl and it is licenced under GNU licence.

It is not only a SCP client, but also SFTP and FTP client too.

Screenshot

Below you can see a Screenshot of WinSCP

Main Features

Some of its main features are:

Full Sync This feature will keep both remote and local folders in sync, so any change you perform in any of the ends of the connection will be updated on the other end. The application should be kept on, and connected to keep this functionality running Sync Remote

This feature will keep only the remote end in sync with the local, so any change made on the local side, will be updated in the remote side. But this will not work in other way. That is any change in remote will not be updated in local.

You can decide to delete remote files or not at the time of starting the syncronization. If you turn it on, any files deleted on local, will be deleted on remote, but if not, only new added files or changes to existing ones will be updated

You can also use the drag and drop feature to copy files from remote to local or viceversa

As you can see, you can optain the same basic functionality for Windows that Linux users already enjoy, and this is maybe the best and easieste way to transfer files from Windows and Linux and viceversa.

If you have suggestions or comments, write to contact at this domain.

Оцените статью