1

I have a shell script which is performing some renaming and archiving steps. I have added sftp commands to copy multiple files. But when i try to login to the remote machine thru putty it asks for confirmation like Are you sure you want to continue connecting (yes/no)? . I need to enter yes. but since this is being done thru the script am not sure how to do it. below is the script i am using

cd <File Source Location>
sftp user1@remoteserver
sftp> cd <target location to be copied>
sftp> mput *.gz 

quit

how to i pass yes in the above code after sftp user1@remoteserver is executed.

Any help is much appreciated.

Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
Warlord
  • 75
  • 2
  • 3
  • 12

1 Answers1

1

I think that you are trying to solve the wrong problem.

sftp asks you for confirmation because it does not know the key of the host yet. Therefore you need to add it to you known_hosts file like this

ssh-keyscan -H remoteserver >> ~/.ssh/known_hosts

I recommend using scp command instead of sftp as it will do all you want in one step.

scp somewhere/*.gz user1@remoteserver:somewhere/else

If for some reason you don't want to do it. You may consider a very insecure command

sftp -o StrictHostKeyChecking=no user1@remoteserver

By using the command above you are vulnerable to Man in the Middle attack, you've been warned.

Grzegorz Żur
  • 47,257
  • 14
  • 109
  • 105
  • thanks @Grzegorz. I added the key in known_hosts. we have to use sftp to copy files so i how to enter the mget command coz when i execute the shell script it executes everything and comes down and wait for me to input the command. is there a way to bypass this so that the script will pass the mget command. – Warlord Oct 18 '13 at 07:23
  • @Sriram Yes, the `scp` command does exactly what you want, it is not interactive unlike `sftp` so you can use it in scripts. – Grzegorz Żur Oct 18 '13 at 07:24