Server Fault is a question and answer site for system and network administrators. 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 made the sftp password less using the ssh -t key_gen option and the prompt for password does not appear anymore but when I write the commands to be executed on the sftp session like the following in the shell script and execute it they are not executed instead i just get the prompt of sftp



sftp $username@$ipaddr
cd $external_path
get *.$extension



and nothing else

Could you please tell how this can be achieved, also the expect utility is there on my machine but the sftp does not support the -b option

Thanks, Priyanka

share|improve this question

sftp username@ipaddress will have sftp enter interactive mode. (Thats why you get an sftp style prompt)

sftp man page

Since you are using sftp programmability, you want to use it in non interactive mode.

sftp $username@$ipaddr:$external_path/filename
#this would work except you need your wildcard * to be expanded

echo "get *" | sftp $username@$ipaddr:$external_path/
#This will work since you are piping the command get * into sftp. 
#* gets expanded by sftp and matching files in $external_path
#Are transfered to your current directory.
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.