How to copy a file from a remote server to a linux/windows host

From Linux with scp:
copy a file from a remote machine to the current directory of the current machine:

sudo scp -p port_number user_name@ip_address:file_path .


For example, i wanted to copy the /etc/ssl/exportcerts/John_Doe_windows_cert.der file from a remote linux server vm3 (192.168.0.2) to the current directory and my username was duck.
The server accepted ssh, so i used port 22.
The command was:

sudo scp -p 22 duck@192.168.0.2:/etc/ssl/exportcerts/John_Doe_windows_cert.der .

Dont miss the dot at the end.

If you want to copy it to a specific directory, replace the last dot with the directory path.

sudo scp -p 22 duck@192.168.0.2:/etc/ssl/exportcerts/John_Doe_windows_cert.der /etc/ssl/certificates

Done.

From Windows with WinSCP:
Just download WinSCP and connect to your server with it to get your files.

WinSCP Interface

Caution: If you try to copy the file in a directory where you need admin privilege to copy (e.g. system32 or program files), it won’t work from WinScp. I made the same mistake first, and it took me an hour to figure it out. Just copy it to your windows desktop via WinScp and the manually copy it to your desired directory.

Good thing is, WinSCP is a SFTP, SCP and FTP client for windows, so i wont need FileZilla anymore.


For my case, it wasn’t all. I needed to copy the file to my laptop. The 192.168.0.2 was a linux host named vm3 and vm3 was accessible only from another multihomed linux host named vm1, which had two ip addresses, 192.168.0.1 or 172.31.212.103
When i generated the file on vm3, i was using putty from my windows 7 laptop to connect via ssh to vm1 (172.31.212.103) first, then ssh again to vm3 (192.168.0.2). With the aforementioned method, i managed to copy the file to vm1 (192.168.0.1 or 172.31.212.103). But still, i needed to get it to my windows 7 laptop from vm1 (172.31.212.103) and i am still not sure if it is possible to get files from a remote server via putty.

So, i used Winscp to connect to vm1 (172.31.212.103) via ssh and copy the file to my windows 7 laptop with just simple drag and drop operation. Why not WinSCP at the first place then? Because, first i needed to login to vm1, then to vm3. and i couldn’t find a way do that kind of inception like operation with WinSCP.

2 responses to “How to copy a file from a remote server to a linux/windows host

  1. I thought I knew a lot there is to know about this thing, but seems we are never to old to learn..;)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s