Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have never done this before and I am creating a bash shell script to do this for me. I will also be connecting via ssh to do some things (which I already know how to do). So maybe there is a way to upload files via ssh so I can do it all in one connection?

How can I do this?


cd ./files-to-upload
#upload the files
share|improve this question
That does not answer this question, but maybe this could help some people: permits you to upload a file through bash to a public http hosting (valid for few hours i think) – Vincent Fenet Nov 19 '15 at 13:58
up vote 42 down vote accepted

You can use scp to copy to a remote machine.

scp <file to upload> <username>@<hostname>:<destination path>
share|improve this answer
can the password be passed with this as well? Also, does this initialize an ssh session? Can I run other commands as well? – Andrew Dec 12 '09 at 21:39
No you cannot pass the password. But you can set up ssh key authentication. That means you do not authenticate via a password but via a key that is stored in a file and automatically transmitted on connection. And no again, you cannot execute other commands with this. – Felix Dec 12 '09 at 22:33
i mean can you connect with ssh, then run scp? Or are they separate commands? – Andrew Dec 12 '09 at 22:34
ssh and scp are different commands. For an introduction see… – tangens Dec 13 '09 at 11:22
@Felix should have pointed out that if you don't have the ssh key authentication set up, you will be prompted for a password. That means, having the that setup is not a critical requirement to use this command – The Sexiest Man in Jamaica Mar 29 at 12:17

You're probably looking for SCP or similar.


cd ./files-to-upload
scp * user@host:/path/to/upload/files/to

of course this must be tweaked to your liking.Replace user@host with your real information. You will be prompted for a password to upload.

share|improve this answer

If you really must use ssh (instead of scp) you can do:

for filename in *; do
  cat $filename | ssh user@host "cd /path/to/upload/files/to; cat - > $filename"

but regular scp (like tangens suggestion) is the best.

share|improve this answer

scp is the better answer since it would be encrypted over SSH.

However, if you do want to do it over standard ftp, look at ncftpput. It's designed specificly to upload a file:

NAME ncftpput - Internet file transfer program for scripts

SYNOPSIS ncftpput [options] remote-host remote-directory local-files...

share|improve this answer

When you use the scp (secure copy) command it connects to the client and if you don’t already have a fingerprint saved for the host device it will ask you for the host password otherwise it should auto connect to the host I believe.

share|improve this answer

curl is a good program that handles several protocols.

share|improve this answer

You must log in to answer this question.

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