24

I know how to get remote file via sftp.

ex:

sftp root@10.0.0.1:/path/to/file.txt localfile.txt

How can i upload file to remote server?

(I need use this command in my bash script.)

ss-t.c
  • 310
  • 1
  • 2
  • 12

2 Answers2

1

Also think about using SSH public/private keys which can avoid you to have to enter a password for your automated file exchanges.

You can use the command "ssh-keygen" to generate those keys.

Flexo
  • 87,323
  • 22
  • 191
  • 272
HelpBox
  • 55
  • 3
-6
$ scp root@10.0.0.1:/path/to/file.txt localfile.txt
vodolaz095
  • 6,680
  • 4
  • 27
  • 42
  • 1
    Ive tried the scp command. It works. Thanks so much! – ss-t.c Jan 12 '14 at 06:52
  • 23
    This won't work if the service allows SFTP connections only (ie, disallows logging in via SSH). – davemyron Sep 23 '14 at 01:04
  • 16
    This is not an answer to the question. SFTP is something different to SCP. The 5 upvotes come obvoisly from people who run SSH and SFTP servers on the same server. – Kenyakorn Ketsombut Mar 03 '15 at 03:54
  • 4
    This is not an answer - the question was using SFTP ... not SCP – Xofo Mar 11 '15 at 18:58
  • looking for sftp, not scp – amulllb May 25 '16 at 06:43
  • Warning, see @ss-t.c 's comment above. If you are trying to upload a file, this will fail (if the remote file does not exist) or download the file instead! – Robert Dundon Jun 01 '18 at 01:23
  • yeah~~ this answer can upload the file in most situations. because most server allow login vis ssh. If you wanna do a real sftp upload see @oliver 's comment above. (http://stackoverflow.com/a/16723151/2148773) – ss-t.c Jun 15 '18 at 07:30