I'm using Linux [centos] machine, I already connected to the other 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
?
asked Dec 24, 2013 at 9:43
6
Syntax:
scp
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
HalosGhost
4,62410 gold badges31 silver badges40 bronze badges
answered Dec 24, 2013 at 9:48
DopeGhotiDopeGhoti
69.6k8 gold badges94 silver badges131 bronze badges
22
In case if you need an alternate approach.
Install sshfs. if you use ubuntu/debian:
sudo apt-get install sshfs
or, if you use centos/rhel:
sudo yum install fuse-sshfs
or, in macOS
brew install sshfs
Create an empty dir
mkdir /home/user/testdir
"link" or "mount" the two directories
sshfs :/remote/dir /home/user/testdir
"unlink" the dirs
fusermount -u /home/user/testdir
On BSD and macOS, to unmount the filesystem:
umount mountpoint
or
diskutil unmount mountpoint
For more see here, linuxjournal.com libfuse/sshfs
Rakib Fiha
5623 gold badges9 silver badges23 bronze badges
answered Dec 24, 2013 at 9:58
Ruban SavvyRuban Savvy
8,0917 gold badges28 silver badges43 bronze badges
8
Sometimes you need to get fancy with tar:
tar -C / -cf - \
opt/widget etc/widget etc/cron.d/widget etc/init.d/widget \
--exclude=opt/widget/local.conf |
ssh otherhost tar -C / -xvf -
answered Dec 24, 2013 at 15:17
Dan GarthwaiteDan Garthwaite
7,3261 gold badge14 silver badges9 bronze badges
7
If you want
to keep the files on both systems in sync then have a look at the rsync
program:
[see tutorial here]
answered Dec 24, 2013 at 21:30
KiffinKiffin
4683 silver badges5 bronze badges
1
If they are running SCP / SSH on a different port, make sure you specify the uppercase -P
port option.
Example:
scp -P 7121 /users/admin/downloads/* :/home/
answered Feb 6, 2021 at 20:13
CarterCarter
3012 silver badges3 bronze badges
2
A simpler method that works with via SSH controlled NVIDIA Jetson computers is to connect with SFTP [SSH File Transfer Protocol].
Suppose I wish to move the document UFO_blueprint.odt
from NASA's remote servers and move it into my Documents.
cd
to where you want the file saved$ cd Documents
Connect
$ sftp sammy@your_server_ip_or_remote_hostname
Go the directory that contains the file to be transferred.
$ cd NASA/secret_files/
Transfer
$ get UFO_blueprint.odt
To get the complete directory, instead use
$ get -r secret_files/
AdminBee
19.6k16 gold badges44 silver badges67 bronze badges
answered Oct 1, 2020 at 3:53
Pe DroPe Dro
1,1501 gold badge6 silver badges13 bronze badges
2
Unix/Linux recursive copy of files and folders over a secure shell using the code following:
scp -r
A full example might look like:
scp -r sizwe@hprobook:./home/sizwe/PycharmProjects ./home/immaculate/OtherPycharmProjects
Note if you do not have a DNS server to resolve hostnames, use your IP address instead. The example above might look like this
scp -r 192.168.43.167:./home/sizwe/PycharmProjects ./home/immaculate/OtherPycharmProjects
AdminBee
19.6k16 gold badges44 silver badges67 bronze badges
answered Nov 9, 2020 at 11:32
SizweSizwe
711 silver badge1 bronze badge
If speed [and not security] is your priority, then check out netcat. Before I start, let me warn you that this should be used only in a trusted network because netcat transfers are not encrypted.
First, on the receiving side, run this:
nc -lp 22222 >FileName
Then on the sending side:
nc -w3 22222 root.tgz
answered Aug 4, 2020 at 19:09
1