From owner-freebsd-questions Mon Nov 2 14:15:24 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id OAA15292 for freebsd-questions-outgoing; Mon, 2 Nov 1998 14:15:24 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from ralf.serv.net (ralf.serv.net [205.153.153.77]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id OAA15257 for ; Mon, 2 Nov 1998 14:15:20 -0800 (PST) (envelope-from mcglk@ralf.serv.net) Received: (from mcglk@localhost) by ralf.serv.net (8.8.5/8.8.5) id OAA08215; Mon, 2 Nov 1998 14:15:02 -0800 (PST) Date: Mon, 2 Nov 1998 14:15:02 -0800 (PST) Message-Id: <199811022215.OAA08215@ralf.serv.net> From: Ken McGlothlen MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: Steven P Yang Cc: freebsd-questions@FreeBSD.ORG Subject: Re: how do I automate ftp? (clarification) References: <199811021917.OAA13614@scrubbing-bubbles.mit.edu> X-Mailer: VM 6.33 under Emacs 19.34.1 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG Steven P Yang (spyang@mit.edu) used the evil N-word when he wrote: | Hi, about my last e-mail, a specific goal I have in mind for an automated ftp | would be the ability to schedule a file transfer at a specific time to a | remote ftp server. So, this implies that the ftp script would automatically | supply the username and password. I can do this on NT, but don't know if I | can do this on FreeBSD. | | Is this possible? Of *course* it's possible, Steven. In a wide variety of ways. Something that would provide a lot of flexibility down the road (if this application got more complicated), but starts off pretty simple, would be the following Perl script: #!/usr/bin/perl use Net::FTP; $serv = "bargle.fleen.org"; $user = "wibble"; $pass = "narfpoit"; $ftp = Net::FTP->new( $serv ); # Create the FTP object $ftp->login( $user, $pass ); # Log in. $ftp->binary(); # Change to binary mode. $ftp->cwd( "/pub/wibble" ); # Change directories. $ftp->mkdir( "floompf" ); # Create a directory. $ftp->put( "farble.txt" ); # Put a file. $ftp->get( "elbraf.txt" ); # Get a file. $ftp->quit(); # Ends the session. You could do something similar in tcl or even sh, but I like Perl. Once your script works, you can schedule it easily enough using the crontab facility. crontab allows you to edit a file called (oddly enough) crontab that looks something like this: # DO NOT EDIT THIS FILE - edit the master and reinstall. # (/tmp/crontab.9722 installed on Sun Oct 18 22:31:43 1998) # (Cron version -- $Id: crontab.c,v 1.6 1996/08/05 00:50:02 pst Exp $) SHELL=/bin/sh PATH=/etc:/bin:/sbin:/usr/bin # #mn hr dy mo wd command * */2 * * * /home/wibble/bin/scriptname Crontab, like Perl, uses "#" as a comment-to-end-of-line indicator. This crontab defines two environment variables, and then sets up the script you just wrote (here called /home/wibble/bin/scriptname) to run once every two hours. Note that if you wanted the script to run at midnight on the 1st and the 15th of every month, that line would read: 0 0 1,15 * * /home/wibble/bin/scriptname If you take a look at the crontab manpage ("man 5 crontab"), you could find out more about this. I daresay that this winds up being a *lot* more flexible than NT's version. Good luck. If you have any questions, let me know. ---Ken To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message