homepage Welcome to WebmasterWorld Guest from 54.242.18.190
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
scripting file transfer through ssh or sftp
ssh or sftp file transfer
mikejson




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

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




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

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




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

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

For copying whole sites, I use rsync over ssh.

jtara




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved