Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

#!/bin/sh

username=$1
ipaddr=$2
external_path=$3
extension=$4

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

Result

sftp>

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

1 Answer 1

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

 
discard

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.