Copying files to/from remote PC in the CLI

Tips and Tricks for Networking

Moderator: jkerr82508

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Copying files to/from remote PC in the CLI

Postby viking60 » 13 Oct 2012, 11:46

We all know the lovly SSH where we can log in to remote PC's and if you can do it via Dolphin or Nautilus we can drag and drop files between them, But believe me; sometimes that does not work!
So you are stuck in your CLI and want to copy files to and from your remote box to finish that all important project in Greenland or on the Bouvet islands.
What to do?

Enter SSH's brother secure copying; scp - if you have set up SSH with keys and pasword-less login it will work with scp too.
So here we go: to copy from a remote box:

Code: Select all

scp berserk@viking-pc:/home/berserk/berserkfiles/document.txt ~/berserkfiles/document.txt

This will copy document.txt from your remote berserfiles directory to your local berserkfiles directory.
To copy entire directories you can use the -r switch like this:

Code: Select all

scp -r berserk@viking-pc:/home/berserk/berserkfiles ~/

This will copy the berserkfiles directory to ~/

To copy to a remote box:

Code: Select all

scp ~/berserkfiles/document.txt berserk@remote-pc:~/berserkfiles/document.txt


If you are using other ports than 22 you will need to specify the port:

Code: Select all

scp -P 40065 ~/berserkfiles/document.txt berserk@remote-pc:~/berserkfiles/document.txt


Usefull stuff!
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Copying files to/from remote PC in the CLI

Postby rolf » 13 Oct 2012, 13:02

:B

Code: Select all

hsftp is an FTP emulator that provides the look and feel of an FTP session,
but uses ssh to transport commands and data. It is written in C, and requires
no additional libraries.


I've used ftp with the `cd` and `dir` commands on public servers, a little. I hear there are `get` and `put` for moving files back and forth. Maybe one of the sftp programs would work for this, as well. :berserk2

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Copying files to/from remote PC in the CLI

Postby viking60 » 13 Oct 2012, 13:31

rolf wrote::B

Code: Select all

hsftp is an FTP emulator that provides the look and feel of an FTP session,
but uses ssh to transport commands and data. It is written in C, and requires
no additional libraries.


I've used ftp with the `cd` and `dir` commands on public servers, a little. I hear there are `get` and `put` for moving files back and forth. Maybe one of the sftp programs would work for this, as well. :berserk2


sftp is SSH and way more secure than ftp so hstfp sounds good. :s I doubt that scp will work with regular ftp because the whole point is the security.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Copying files to/from remote PC in the CLI

Postby rolf » 13 Oct 2012, 13:44

That's right. I'm suggesting one of the secure ftps that use ssh could work like scp. :greetings

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Copying files to/from remote PC in the CLI

Postby viking60 » 13 Oct 2012, 15:10

Aha got it!
It sounds like they will work since it is the same protocol. I cannot see any reason why not....
Since I use the RSA key this would apply to me:
For RSA authentication, you can avoid to have hsftp caching the passphrase if you use ssh-agent. In this case, you can use hsftp securely without setting it SUID root.

I am instaling it now, thanks for the tip!
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Copying files to/from remote PC in the CLI

Postby viking60 » 13 Oct 2012, 15:27

Confirmed! :s
I normally just do a

Code: Select all

ssh berserk-pc
since I have exhanged RSA keys with the host and set pasword-less login.
So I simply replaced SSH with hsftp

Code: Select all

hsftp berserk-pc
and poped right in there :B Now I only have to figure out how to use it... :think:
Hey this thing is great!
I just did a

Code: Select all

get somefile
and it downloaded it without a question. So I wondered where it landed - and it seems to go to the current directory on your box.
Oh man this thing is way easier!
You are the Guru indeed +1
:bowlol Image
Having said that I am a bit cross with you for leting me work the hard way while you have been sitting on this secret all along.... :naughty:
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Copying files to/from remote PC in the CLI

Postby rolf » 13 Oct 2012, 17:26

:dance1 Not so. I just saw a connection with something I remembered and looked up something sftp on Mandriva.
You won't catch me doing that sort of heavy lifting anytime soon! Image

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Copying files to/from remote PC in the CLI

Postby viking60 » 13 Oct 2012, 18:30

You are forgiven: Berserks are civilized you know!
I was wondering how the put comand would work and I found out:

1 go to the directory you want to copy from on your local box
2 hsftp into your remote box from there
3 do a

Code: Select all

put somefile
and it will be copied from your local directory to the current directory on the remote box.

GREAT! :B
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"

User avatar
rolf
Guru-Berserk
Posts: 1107
Joined: 16 Mar 2010, 16:07

Re: Copying files to/from remote PC in the CLI

Postby rolf » 13 Oct 2012, 18:45

Good stuff. :s

User avatar
viking60
Über-Berserk
Posts: 9351
Joined: 14 Mar 2010, 16:34

Re: Copying files to/from remote PC in the CLI

Postby viking60 » 21 Oct 2012, 20:25

Since hsftp seems to be something Mandriva and Arch have and nobody else I started the campaigh of getting in into other distros and the Mageia guys tipped me of lftp.
This works too if you remember to prepend your command with a !
And it does not correctly indicate in what directory you are...In fact I am not able to change directory.
Manjaro 64bit on the main box -Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz and nVidia Corporation GT200b [GeForce GTX 275] (rev a1. + Centos on the server - Arch on the laptop.
"There are no stupid questions - Only stupid answers!"


Return to “Networking”