Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copying a local file from Mac to an ssh session in terminal [closed]

I'm new to using bash commands and having some trouble. I'm ssh'ing into a linux box which contains some of my work files. I have a local file on my mac which I need to copy onto the server.

Here are the steps I've gone through so far: 1) ssh [email protected] 2) Entered password 3) pwd 4) working directory: home/usrname

I'm stuck after this. I have a local folder in documents in my mac. I want to copy it to my working directory on the server I"m ssh'ed into.

Appreciate your help. Thanks

like image 574
ixbo45 Avatar asked Sep 12 '16 19:09

ixbo45


2 Answers

When you ssh to a remote machine, then it's as if you are sitting in front of that other machine and execute commands in it. While you are in that state, you cannot copy file to (or from) it. Instead you have to use a different tool, scp, which also belongs in the ssh family and in fact calls ssh behind the scenes. This is how you copy a local directory to a remote machine:

scp -rp /path/to/local/dir [email protected]:/path/to/remote/dir

I used the -r mode (which stands for recursive) to copy the directory recursively. See also the manual of scp for more details

like image 153
redneb Avatar answered Nov 03 '22 00:11

redneb


You will want to use sftpinstead of ssh for this. Try the following:

  1. sftp [email protected]
  2. Enter password
  3. cd <directory where you want to transfer the file>
  4. put <name of file you want to transfer>

You can also add 'l' before some commands to indicate that you want to do that locally. i.e. ls will display files on the remote server, and lls will display files on the local machine.

EDIT :

You will want to make sure that you either

a. navigate to the folder that contains the file you want to transfer prior to starting the sftp process.

b. use lcd and lls once you are in the sftp session to navigate to the local folder that contains the file you want to transfer.

As mentioned in the comments, using the full path to the file you want to transfer doesn't work.

like image 24
Malcolm G Avatar answered Nov 03 '22 00:11

Malcolm G