Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I transfer files using this command

scp <localfile> user@host:<destination>

The above command only works when I'm not ssh'd into the server.

How do I transfer local files to the host machine when I'm already ssh'd in??

I ssh in using ssh user@hostname

share|improve this question
2  
What OS? Open up another terminal and use the scp command –  Impulss Mar 8 '13 at 23:04
1  
it is centOS. Thats what I've been doing so far. I was just hoping for something more convenient. –  Omnipresent Mar 8 '13 at 23:22

4 Answers 4

Nice question. scp again, but the opposite way. I did it and here it is:

chris@local ~$ ls hos*
hosts
chris@local ~$ ssh remote
Last login: Fri Mar  8 15:52:25 2013 from local
chris@remote ~$ scp chris@local:hos* .
chris@local's password: 
hosts                                              100% 1850     1.8KB/s   00:00    
chris@remote ~$ ls hos*
hosts
chris@remote ~$ 

edited to add: as pointed out in the comments, this requires that the remote computer can access the local computer. And sshd or (openssh-server) needs to be installed and running on the local machine.

share|improve this answer
2  
This suppose the local machine is accessible from the remote one and this is not always true. –  laurent Mar 9 '13 at 0:51
    
However, if it is true it will work nicely. –  daviewales Mar 9 '13 at 4:08

It would help to know what you're running on the host machine. If you're using Linux,

scp user@host:/path/myfile .

should work.

share|improve this answer
    
user@host is the remote machine from what I understood on Question so this command will not copy files from the local machine to the remote one but from the remote to the local if not SSHed in the host and will copy from the remote to itself if SSHed. –  laurent Mar 9 '13 at 0:54
    
I think there is some ambiguity in the question. To me, user@host appears to refer to whichever computer you are not currently controlling. So, when the OP is not logged into the remote computer, then user@host is the remote computer. When the OP is logged into the remote computer, then user@host is the local computer. If my assumptions are correct, then this answer makes sense. –  daviewales Mar 9 '13 at 4:14
    
That's exactly how I interpreted the question as well, daviewales. Also, you are correct, user@host would represent whatever workstation your're currently NOT working from, in my opinion. I debated on whether to make that more clear in my response, but figured it would be implied. –  Josh R Mar 9 '13 at 4:20
    
Anyways, even if user@host represents the local machine when the user is logged on the remote machine (unlikely as the OP said he wants to transfer local files to host machine), this will work only if the local machine is accessible from the remote on (usually if they are in same LAN) and not in a scenario where the remote machine is on the internet and the local machine has no fixed IP. –  laurent Mar 9 '13 at 14:56

If you have a way back to your local machine (your local machine is accessible from the remote one - usually when both machines are in same LAN), using scp from the remote machine should work (scp local:/path-to-file .).

If your local machine cannot be reached from the remote one (usually true if your remote is a VPS on the internet and your local machine has a dynamic IP), your best way is to open a new terminal on local machine and copy the file.

Another way, more complicated and certainly not necessary only to copy file would be to make a VPN between the machines (or networks) so both machines would be reachable from the other and you could use scp from one machine or from the other.

share|improve this answer

while logged into remote system(easier to just cd into file location) sudo scp file_location/file_name user@host:file_location

while logged out of remote system sudo scp authoried_user@hostname:file_location/file_name new_location_on_local_machine

FOOTNOTE: remember, while logged out of remote systems, if its a new terminal, the first password will be sudo password, 2nd password will be authorized user password. if you've sudo-ed before in that particular terminal, then its just the authorized user password u need. watch for these, it makes it tricky.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.