• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Batch FTP/SFTP scripts in UNIX/BSD

Superwormy

Golden Member
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!
 
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.
 
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.
 
ssh keys without password. if the eys are not accessible outside the cron job it is even reasonably secure.
 
Back
Top