I want a file to be uploaded daily to remote server using automated ftp command. Can someone please help me on this below command to check whether it's right or wrong?

curl -Tu username:password /path/to/dir/*(om[1]) sftp://sftp.example.com/remote/dir


  • username:password is my own username and password.

  • /path/to/dir/*(om[1]): to get the latest(updated) file from my local dir

  • sftp://sftp.example.com/remote/dir: secure file transfer

  • 3
    Do you get any errors when you run this, what have you done to get the answer so that you know first if it is right or wrong?
    – vgoff
    Nov 21, 2012 at 1:42

2 Answers 2


Your command line has a problem that you can check on the man page. Basically you need to separate the -T <file to be uploaded> from the -u <user:password>. In the end your command line should look more like:

curl -T /path/to/dir/*(om[1]) -u username:password sftp://sftp.example.com/remote/dir

I am not sure about the actual meaning of the regular expression you mention *(om[1]), though.

Of course, in case SFTP is used, you can use a private SSH key for authentication instead of username and password as per --key and --key-type options. See documentation linked above for details.

Finally, the question is about FTP while the command line example is about SFTP, but this shouldn't change the solution I am proposing.

  • Does this still work with ssh keys? Aside from the fact that specifying passwords on command lines is insecure, ssh keys are more secure still. Nov 21, 2021 at 21:15
  • Yes, of course they do.
    – EnzoR
    Nov 23, 2021 at 7:42
  • Update: For SSH keys you want something like --key path/to/key --pubkey path/to/key.pub for specifying the private & public SSH keys respectively. Nov 23, 2021 at 13:28
  • When you connect to a server via SFTP/SCP/SSH you don't mind about public keys: those need to be already in place in the server. I updated my answer to reflect the "ability".
    – EnzoR
    Nov 24, 2021 at 14:24

Why not rsync instead? You may have to install it (use your package manager), but it's made for this kind of thing.

RSYNC_PASSWORD='password' rsync -rtv /path/to/dir/ [email protected]:remote/dir

-r will recursively rsync, -t preserves time stamps so existing files aren't re-uploaded (effectively), and -v is verbose.

If you create and copy your ssh public key, you won't need to do the RSYNC_PASSWORD='password' part.

If you don't have a public/private key combination, run:



ssh-copy-key-id [email protected]

This assumes your remote server supports connecting and updating the $HOME/.ssh/authorized_keys file; otherwise, you'll have to manually upload the authorized_keys file with your public key.

This assumes you're running a recent version of linux. Unix systems like Mac OS don't have the ssh-copy-key-id. Here's some more information on generating and installing your public key on a remote host:


  • 3
    Your point is irrelevant, as OP uses a curl command.
    – laebshade
    Sep 12, 2017 at 19:51
  • One downside with rsync is that it requires a shell account, something that SFTP doesn’t require. I.e. more attack surface. Apr 12, 2021 at 13:31

You must log in to answer this question.

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