Welcome to WebmasterWorld Guest from 54.227.5.198

Forum Moderators: bakedjake

Message Too Old, No Replies

scripting file transfer through ssh or sftp

ssh or sftp file transfer

     

mikejson

6:52 pm on Oct 30, 2006 (gmt 0)

10+ Year Member



Hey there!

Just curious if anyone could help me with this.

I'm trying to write a script that can transfer files from 1 machine to another through ssh.

Unix machine, ksh, OpenSSH, and a version of sftp.

I can automate everything except the pass when doing sftp.

I just do something similar to the below

sftp -b /devfd/0 user@mysshserver << EOF
cd /tosomewhere
mput *.txt
bye
EOF

I however now have a nightly process that I wish to script the entire process(including the password). For some reason, the things I've tried do not work, either SFTP doesn't support what I thought would work, or I can't seem to get the SSH scripting correct. It errors out, and I can't clean it up.

Can anyone suggest a way for me to do my file transfer totally scripted?

jtara

10:36 pm on Oct 31, 2006 (gmt 0)

WebmasterWorld Senior Member jtara is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Use public/private keypairs instead of passwords. You will need to create a private key that does not require a passphrase. The private key goes on the "connecting" machine, the public key on the "connected-to" machine.

This is a bit of a security risk, though, because if somebody gains acces to the "connecting" machine, they then can gain access to the "connected to" machine.

However, you can mitigate this by restricting SSH use for that keypair to only your script. If you have multiple scripts, you can create multiple keypairs, and have each one restricted to a specific script.

danny

7:02 am on Nov 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suggest using scp instead of sftp, with ssh keys as suggested.

For copying whole sites, I use rsync over ssh.

jtara

9:34 am on Nov 4, 2006 (gmt 0)

WebmasterWorld Senior Member jtara is a WebmasterWorld Top Contributor of All Time 5+ Year Member



Doh! You're right. scp will do the same thing, but is easier to script. sftp is intended to be an interactive tool. scp is a better choice for scripting.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month