1

I know how I can send files to a specific directory on a remote server using ssh, but I don't know how to specify it.

0

2 Answers 2

10

There are a few methods.

The simplest way if you're just transferring a file once in a while.

scp myfile.txt [email protected]:/home/user/

scp stands for secure copy and it transfers over SSH.
There is also sftp

sftp [email protected]
> cd /home/user/
> put myfile.txt

I guess the only real advantage to using this is that you can transfer multiple files without typing in your SSH password all the time. (If you don't use a keyring that is)

If you're going to be regularly transferring files take a look at rsync. A simple usage of rsync might look like:

rsync mydir/ [email protected]:/home/user/

But take a look at the man page as there are tons of options.

Finally, there is a sshfs. With this method you can mount an SSH server to your local filesystem like any other filesystem, then you can just copy files into it.

sshfs [email protected]:/home/user/ /mnt/ssh/
cp myfile.txt /mnt/ssh/
3
  • Another trick if you want to transfer multiple files at once is to do ssh [email protected] 'tar -c /path/to/file1 /path/to/file2' | tar -C / -x or to send tar -c /path/to/file1 /path/to/file2 | ssh [email protected] 'tar -C / -x'
    – phemmer
    Feb 3, 2011 at 22:52
  • @Patrick nice one; however you can just scp file1 file2 file3 fileN [email protected]:. Another useful one is scp user@server:/path/file anotheruser@anotherserver:/path2/file2.
    – guido
    Feb 24, 2011 at 20:11
  • If you just write scp myfile.txt [email protected]:, the file is copied to the user's home directory. More generally, the remote path is relative to the home directory (unless it begins with / of course). Feb 24, 2011 at 20:51
3

Technically, the answer to your question is that you must specify where the file is. There is no magic.

For instance with SCP (which uses the SSH protocol) you would specify username@systemname:pathtofile

SCP then logs in to the system that you specify using the username and follows the path that you specify to find the file.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .