2

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

1 Answer 1

2

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.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .