I want to use a shell script to pull a file from another server. I have written a script where i can do this but i want the script to work non-interactively so that it doesn't prompt me for the password and works automatically if i hard-code the same and let the script have what it needs.
I have done this before for FTP
however, in out new servers the FTP
connections are blocked and we can use only SCP
or SFTP
. My earlier script was something like this which used to work with FTP
and did the job well without asking for the password:
#!/bin/bash -vx
ftp -in 100.XXX.XXX.XX<<END_SCRIPT
quote USER username
quote PASS password
bin
prompt off
cd /directory/in/remote/host
lcd /directory/in/local/machine
mget *
bye
END_SCRIPT
I tried the similar for SFTP
in a script and it works for Interactive mode but like FTP
i am not able to use the non-interactive options for SFTP
. Following is my code to fetch particular files from the remote machine:
#!/bin/bash -vx
path="/tmp/testanks"
sftp username@100.XXX.XX.XXX <<EOT
cd $path
get Bharti*
quit
EOT
How can i change the above code in a way that i could provide this script the username and password to make it non-interactive.
I understand that providing a hard-coded password is a security concern but right now i am concerned more about fetching the files immediately. I would really appreciate if i could get the secured ways of doing it as well along with the answer i desire.
scp
has issues on multiple big files or huge number of small files, in which case you could usersync
, however you'll needrsync
on both machines wherescp
only needs to be on machine running the script. – gwillie Jul 31 '15 at 08:11scp
and enforcessftp
. I tried to usescp
and got this message: This service allows sftp connections only.. I remember, that this may be due to a chrooted environment which only works with sftp, not scp. (To be confirmed). – Michael Härtl Feb 04 '17 at 11:05