Ashley Ashley - 1 year ago 214
Bash Question

Simple shell/bash based sftp script to upload a file to root directory of destination server

I need to upload a file from source unix server to destination unix server (supports sftp). i'm using simple script below:-

cd /usr/bin

sftp userid@destination_server <<EOF

put myfile /


I get host key verification failed, Couldn't read packet: Connection reset by peer
I know this must have got something to do with correct public ssh key of my source being not set under destination server. But otherwise , is my script correct. Or do you suggest any other script based on my simple requirement stated above. Please note this doesn't need any password, just user name is sufficient and remote directory is just the root directory, hence using /.

Answer Source

Simply use a SFTP batch file:

sftp -b batchfile.sftp userid@destination_server

with batchfile.sftp containing exactly one line (or whatever more commands you should need)

put myfile /
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download