Kuo-Hsien Chang
Kuo-Hsien Chang

Reputation: 935

bash script to sftp files with a password from remote directories to local folders

How to write a bash script using sftp command to download files? I can use the following command to login to the remote machine, however I need to type in the password manually.

bash-3.2$ sftp -o "Port 22022" [email protected]
[email protected]'s password: 
Connected to s-edm-ssh.local.files.stack.com.
sftp>

How to do the sftp without the password prompt?

If I like to download aaa.txt file at /remote/mike/files to my local directory /local/mike/downloaded, how to build a script to do all of these work?

Upvotes: 0

Views: 6877

Answers (1)

chrisaycock
chrisaycock

Reputation: 37930

Since sftp runs over SSH, you can place your public key on the remote server.

If for some reason you can't place your key on the server, then you can write an Expect script to send your password when the prompt appears. See this example.

Upvotes: 5

Related Questions