Transfer file via ssh linux

How to copy files from one machine to another using ssh

I am using a Linux (CentOS) machine, and I have already connected to another system using SSH . Now, my question is: How can I copy files from one system to another system? Suppose, in my environment, I have two system like System A and System B . I’m using System A machine and some other using System B machine. How can I copy a file from System B to System A ? And, copy a file from System A to System B ?

I find scp to be a cumber stone often. If it could suite your needs, try this out linuxjournal.com/article/8904 It mounts the remote file system locally.

somewhat related: make an encrypted archive of local dir/ on remote machine using ssh : tar -c dir/ | gzip | gpg -c | ssh user@remote ‘dd of=dir.tar.gz.gpg’

If you has access of the ftp of the remote server, we can also use wget to download like $wget -r —level=9 —no-parent —reject «index.html*» ftp://:@/path/to Reference1 Reference2

Not duplicate, linked question specifically asks not to use scp ; for that one scp is fine and most easy way as answer, so mods please remove duplicate flag as if somebody will go to other one, most useful answer will be missed out.

12 Answers 12

To copy a file from B to A while logged into B :

scp /path/to/file username@a:/path/to/destination 

To copy a file from B to A while logged into A :

scp username@b:/path/to/file /path/to/destination 

To clarify, you typically don’t use scp to copy a file to or from your local machine (System A) while logged in to a remote server (System B) with ssh . scp will log you into the remote server, copy the file, then log you out again in one process, so just run it from a shell on your local machine. That being said, you can use scp if you’re logged into System B via SSH and want to copy files between System B and System C.

Читайте также:  Встроенный антивирус astra linux

@DopeGhoti. Yes, you can’t move files between two remote computers. Either the source or destination must be a local file. However, if you log in to a remote machine with ssh, you can copy files between two remote machines on that machine’s command-line.

Also, an important thing to remember is that you can only scp to a folder on the target machine to which you have permissions. If you are trying to copy it to a destination to which the target user does not have permission, first copy the file to the user’s home directory or sub directory and then ssh into the target machine and sudo move it over to the final destination

Источник

SSH / TransferFiles

Another important function of SSH is allowing secure file transfer using SCP and SFTP.

Secure Copy (scp)

Just as all modern Unix-like systems have an SSH client, they also have SCP and SFTP clients. To copy a file from your computer to another computer with ssh, go to a command-line and type:

For example, to copy your TPS Reports to Joe’s Desktop:

scp "TPS Reports.odw" joe@laptop:Desktop/

This will copy TPS Reports.odw to /home/joe/Desktop, because SCP uses your home folder as the destination unless the destination folder begins with a ‘/’.

To copy the pictures from your holiday to your website, you could do:

scp -r /media/disk/summer_pics/ mike@192.168.1.1:"/var/www/Summer 2008/"

The -r (recursive) option means to copy the whole folder and any sub-folders. You can also copy files the other way:

scp -r catbert@192.168.1.103:/home/catbert/evil_plans/ .

The ‘.’ means to copy the file to the current directory. Alternatively, you could use secret_plans instead of ‘.’, and the folder would be renamed.

Secure FTP (sftp)

Finally, if you want to look around the remote machine and copy files interactively, you can use SFTP:

Читайте также:  Сервер времени linux windows

This will start an SFTP session that you can use to interactively move files between computers.

SSHFS

SSHFS is a recent addition to Linux that allows you to make a remote filesystem available over SSH act as if it was inside a folder on your own system. See SSHFS for details.

GNOME

Click File -> Connect to Server. Select SSH for Service Type, write the name or IP address of the computer you’re connecting to in Server. Click Add Bookmark if you want to make the connection available later in the Places sidebar. There are options to login as a different User Name, on a different Port number, and use a different default Folder.

Files can be copied by dragging and dropping between this window and other windows.

KDE

Open Konqueror, and in the address bar type:

fish://username@server_address

Files can be copied by dragging and dropping them between this window or tab and to other windows or tabs.

Using other programs

SecPanel and PuTTY also have file transfer utilities, although they’re generally not as easy to use as the ones discussed above.

SSH/TransferFiles (последним исправлял пользователь c-71-237-198-100 2015-01-16 00:19:38)

The material on this wiki is available under a free license, see Copyright / License for details
You can contribute to this wiki, see Wiki Guide for details

Источник

Копирование файлов через SSH

В статье мы расскажем, как копировать файлы в Windows и Linux-системах, и покажем основные команды, с помощью которых происходит передача файлов по SSH.

Для копирования файлов по SSH в Linux-системах и Windows используют разные инструменты:

  • scp (Secure CoPy) — утилита для безопасного копирования данных между Linux-системами по протоколу SSH. Она входит в состав OpenSSH, поэтому для работы с утилитой не нужно устанавливать дополнительное ПО;
  • pscp.exe — утилита для загрузки файлов по SSH в ОС Windows. Она обладает теми же возможностями, что и scp. Утилита входит в состав программы Putty — SSH-клиента для Windows. Скачать программу можно по ссылке.

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

Копирование файлов по SSH на Linux

Для Linux копирование файлов по SSH происходит с использованием команды scp. С её помощью можно копировать файлы:

  • с локального компьютера на удалённый сервер,
  • с удалённого сервера на локальный компьютер,
  • с одного удалённого сервера на другой.
scp [опция] [источник] [получатель]

Как скопировать файл по SSH с локальной машины на удалённый сервер

Как загрузить файл на сервер по SSH? Для этого используйте команду вида:

scp [путь к файлу] [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу]
scp /home/test.txt root@123.123.123.123:/directory

Файл test.txt будет скопирован на хост 123.123.123.123 в директорию «/directory».

Читайте также:  Jre for linux bin

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

При подключённом SSH скачать файл на локальный компьютер с удалённого сервера можно с помощью команды:

scp [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу] [путь к файлу]
scp root@123.123.123.123:/home/test.txt /directory

Файл test.txt будет загружен с сервера 123.123.123.123 на локальный компьютер в папку «/directory».

Как скопировать файл по SSH с одного удалённого сервера на другой

Подключитесь по SSH к серверу, на котором расположен файл. Затем выполните команду:

scp [путь к файлу] [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу]
scp /home/test.txt root@123.123.123.123:/directory

Файл test.txt будет скопирован на хост 123.123.123.123 в директорию «/directory».

Как скачать папку со всеми файлами и подпапками

Если вы хотите скачать папку со всеми файлами и подпапками, используйте ключ -r:

scp -r [источник] [получатель]

Как подключиться к серверу по нестандартному порту

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

scp -P [источник] [получатель]
scp -P 12345 /home/test.txt root@123.123.123.123:/directory

Эта команда подключается по порту 12345 к серверу 123.123.123.123 и копирует на него файл «test.txt» с локального компьютера в директорию «/directory».

Как передать и скачать файлы по SSH на Windows

Скопировать файл по SSH на сервер можно командой:

pscp [путь к файлу] [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу]

Скачать файл по SSH с сервера командой:

pscp [имя пользователя]@[имя сервера/ip-адрес]:[путь к файлу] [путь к файлу]

Увидеть список папок и файлов на сервере можно через pscp.exe. Для этого введите:

pscp -ls [имя пользователя]@[имя сервера/ip-адрес]:[путь]

Если в пути или в названии файла есть пробелы, используйте кавычки:

pscp “C:\files or docs\file name” root@123.123.123.123:/home

Источник

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