Batch FTP/SFTP scripts in UNIX/BSD

Superwormy

Golden Member
Feb 7, 2001
1,637
0
0
I need to have a cronjob for our BSD server that backs up some files.

Basically what I want it to do is copy some folders, tar everything up, then FTP it to our offsite backup machine. The copying and tarring works fine, so now I just need it to FTP.

I can connect to the remote machine, but how can I have the shell script login non-interactivly ( ie make the shell script login on its own, so that it doesn't prompt for username/password and all )

The only information I can' find on this involves something with trading public SSH keys or something... not sure I entirely understand that, but if anyone would walk me through either making a shell script that logs in to an SFTP server and does something, or how to set up the SSH keys so that the user doesn't need to provide a password but is still secure and logged in...

I'd much appreciate any help! Thanks!
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I was doing something similar at work and while it's definatly possible and not that hard (not that I remember the specifics right now) I found it frustrating to write a decent script because the CLI ftp on the host I was writing it for returned 0 no matter what happened so there was no way to do error checking to see if the transfer completed. I gave up and rewrote the script in perl using Net:FTP.

You could also use the scp or sftp method if you have an SSH server handy, doing public key authentication isn't terribly hard and is probably a better idea than storing a username/password in a file somewhere on the system.
 

n0cmonkey

Elite Member
Jun 10, 2001
42,936
1
0
For FTP: .netrc

But it's horribly insecure.

IBM had a nice document on setting up SSH keys a few years ago. It shouldn't be tough to get it setup. Turn off passwords, make a key, and set it up to use that key.
 

uOpt

Golden Member
Oct 19, 2004
1,628
0
0
ssh keys without password. if the eys are not accessible outside the cron job it is even reasonably secure.