Bernard
Bernard

Reputation: 4580

Copying file from ssh server to mac?

This question has been repeated many times and I know to copy a file from ssh server to mac I should follow this:

Copy the file "foobar.txt" from a remote host to the local host

$ scp [email protected]:foobar.txt /some/local/directory

But I want to know how can I copy that to my local machine after connecting to remote ssh. I meant after connecting to ssh means in terminal I connect to ssh and then I copy them to my pc. what I want to do is one time connect to ssh and enter password and then do all operation. Why? because I am writing a user friendly program which ask password one time and I don't want the user enter every time or save the password.

Upvotes: 3

Views: 10472

Answers (3)

noone
noone

Reputation: 6558

You can copy files from remote to local by sftp (secure file transfer protocol) first init sftp

sftp -P typeYourPortNumber username@hostname

now you are inside of sftp terminal. now you can copy file by typing

get absolutePathToSouce absolutePathLocal

you also can transfer file to the server by

put pathToSource pathToDestination

Upvotes: 0

Aleks-Daniel Jakimenko-A.
Aleks-Daniel Jakimenko-A.

Reputation: 10653

You're actually trying to reuse existing ssh connection.

Add this to your ~/.ssh/config to set up automatical connection sharing:

ControlMaster auto
ControlPath ~/.ssh/control:%h:%p:%r

Now, if you do

scp [email protected]:foobar.txt /some/local/directory

And if you already have a connection established in another terminal then it wont ask you for a password and connection will be established very quickly.

Upvotes: 2

paulsm4
paulsm4

Reputation: 121649

Not an SO question, but:

http://kb.iu.edu/data/agye.html

The syntax for the scp command is:

scp [options] username1@source_host:directory1/filename1 username2@destination_host:directory2/filename2`

In other words, just switch source/destination if you want to copy something in the other direction :)

For example:

scp foobar.txt [email protected]:some/directory

Upvotes: 0

Related Questions