Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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.

share|improve this question

2 Answers 2

up vote 10 down vote accepted

There are a few methods.

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

scp myfile.txt user@example.com:/home/user/

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

sftp user@example.com
> 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/ user@example.com:/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 user@example.com:/home/user/ /mnt/ssh/
cp myfile.txt /mnt/ssh/
share|improve this answer
    
Another trick if you want to transfer multiple files at once is to do ssh user@example.com 'tar -c /path/to/file1 /path/to/file2' | tar -C / -x or to send tar -c /path/to/file1 /path/to/file2 | ssh user@example.com 'tar -C / -x' –  Patrick Feb 3 '11 at 22:52
    
@Patrick nice one; however you can just scp file1 file2 file3 fileN user@example.com:. Another useful one is scp user@server:/path/file anotheruser@anotherserver:/path2/file2. –  guido Feb 24 '11 at 20:11
    
If you just write scp myfile.txt user@example.com:, 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). –  Gilles Feb 24 '11 at 20:51

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.

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.