Posted: . At: 1:27 PM. This was 10 years ago. Post ID: 7480
Page permalink. WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters.
These cookies expire two weeks after they are set.

How to copy files from one machine to another using SSH and the sftp command.

The sftp command allows a user to retrieve files on a remote machine and save them on their computer.

Use this command to access the files: sftp -P 443 [email protected]:/home/homer/Downloads/*.pdf I have my SSH server running on port 443, so I need to specify that port when using this command. I am using Cygwin on Windows Server 2012 R2, but this will work the same way on a Linux client.

Administrator@WIN-EM8GK0ROU41 ~
$ sftp -P 443 homer@192.168.100.2:/home/homer/Downloads/*.pdf
homer@192.168.100.2's password:
Connected to 192.168.100.2.
Fetching /home/homer/Downloads/George_Martin_-_A_Game_of_Thrones.pdf to George_Martin_-_A_Game_of_Thrones.pdf
/home/homer/Downloads/George_Martin_-_A_Game_of_Thrones.pdf                                                                            100% 5905KB   1.9MB/s   00:03
Fetching /home/homer/Downloads/ISBSprogram6_16.pdf to ISBSprogram6_16.pdf
/home/homer/Downloads/ISBSprogram6_16.pdf                                                                                              100% 1911KB   1.9MB/s   00:01
Fetching /home/homer/Downloads/codenomicon-wp-smart-tv-fuzzing.pdf to codenomicon-wp-smart-tv-fuzzing.pdf
/home/homer/Downloads/codenomicon-wp-smart-tv-fuzzing.pdf

This is a perfect way to access a file on your home server machine if you left it behind and you have SSH access.

Administrator@WIN-EM8GK0ROU41 ~
$ ls -hula
total 12M
drwxr-xr-x+ 1 Administrator None    0 Jul  3 13:19 .
drwxrwxrwt+ 1 Administrator None    0 May 22 05:10 ..
-rw-------  1 Administrator None 1.6K May 22 05:30 .bash_history
-rwxr-xr-x  1 Administrator None 1.5K May 22 05:07 .bash_profile
-rwxr-xr-x  1 Administrator None 6.0K May 22 05:07 .bashrc
drwx------+ 1 Administrator None    0 May 22 05:29 .cache
drwx------+ 1 Administrator None    0 May 22 05:29 .config
-rwxr-xr-x  1 Administrator None 1.9K May 22 05:07 .inputrc
drwx------+ 1 Administrator None    0 May 22 05:29 .local
-rw-r--r--  1 Administrator None  116 May 22 05:19 .minttyrc
-rwxr-xr-x  1 Administrator None 1.3K May 22 05:07 .profile
drwx------+ 1 Administrator None    0 Jun  6 15:52 .ssh
-rw-r--r--  1 Administrator None 3.9M Jul  3 13:19 codenomicon-wp-smart-tv-fuzzing.pdf
drwxr-xr-x+ 1 Administrator None    0 May 23 11:19 Documents
-rw-r--r--  1 Administrator None 5.8M Jul  3 13:19 George_Martin_-_A_Game_of_Thrones.pdf
-rw-r--r--  1 Administrator None  12K May 22 12:23 index.html
-rw-r--r--  1 Administrator None  12K May 22 12:27 index.html.1
-rw-r--r--  1 Administrator None  12K May 23 11:13 index.html.2
-rw-r--r--  1 Administrator None 1.9M Jul  3 13:19 ISBSprogram6_16.pdf
-rw-r--r--  1 Administrator None   78 May 23 11:14 my.c
-rw-r--r--  1 Administrator None 2.7K May 23 11:18 my.o

Now I have the files on my local machine. This is one very useful trick to use when you are accessing an SSH server.

1 thought on “How to copy files from one machine to another using SSH and the sftp command.”

Leave a Reply to RoseHosting Cancel reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.