Copy file from Windows to Linux SSH

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

Copy file from Windows to Linux SSH

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

Copy file from Windows to Linux SSH

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.

  1. cd to where you want the file saved

    $ cd Documents
    
  2. Connect

    $ sftp sammy@your_server_ip_or_remote_hostname
    
  3. Go the directory that contains the file to be transferred.

    $ cd NASA/secret_files/
    
  4. 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

Copy file from Windows to Linux SSH

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

Notes:

  • -l: Listen mode
  • -p: Port number to listen on (I picked an arbitrary port)
  • -w: Connect timeout

answered Apr 28, 2021 at 7:14

If you have one of the common OSes, you can install pigz that is the same as gzip except that it will use multiple cores and be quicker over a fast network. My command is a bit different.

tar cf - -C /opt -S  | pigz | ssh  "pigz -d | tar xf - -C /opt -S"

or the other way to get files

ssh  "tar cf - -C /opt -S  | pigz" | pigz -d | tar xf - -C /opt -S

or backup the root fs with

ssh  "tar cf - -C / --one-file-system -S --numeric-owner . | pigz" > root.tgz

answered Aug 4, 2020 at 19:09

1

How do I transfer files from Windows to Linux?

4 Ways to Transfer Files From Windows to Linux.
Securely copy files via SSH..
Windows to Linux file transfer with FTP..
Share data using sync software..
Use shared folders in your Linux virtual machine..

Can I use SSH to copy files?

Often you will need to move one or more files/folders or copy them to a different location. You can do so using an SSH connection. The commands which you would need to use are mv (short from move) and cp (short from copy).

Can you SSH from Windows to Linux?

Use the open source tool, PuTTY to establish an SSH connection from a Windows machine to a Linux system. The secure shell protocol (SSH) is the most common method for controlling remote machines over the command line in the Linux world.