home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!uknet!ox-prg!bush
- From: bush@ecs.ox.ac.uk (Mark Bush)
- Newsgroups: comp.lang.perl
- Subject: Re: How to wait for a pipe to complete a task?
- Message-ID: <4288@inca.comlab.ox.ac.uk>
- Date: 14 Aug 92 16:41:26 GMT
- References: <1992Aug14.145310.29093@raid.dell.com>
- Sender: news@comlab.ox.ac.uk
- Organization: Oxford University Computing Laboratory
- Lines: 76
-
- In article <1992Aug14.145310.29093@raid.dell.com> painter@manufing.dell.com (Tom Painter) writes:
- #I need to write a program with batch FTP. I keep hitting the following
-
- There are probably a number of ways of doing what you want, however the
- following script which uses chat2 is what I use for doing backgrounded FTP
- jobs at suitable hours. I have a version of chat2 which I call chat2verbose
- which is obtained using the following patch:
-
- *** /usr/local/lib/perl/chat2.pl Mon Dec 9 16:32:01 1991
- --- /usr/local/lib/perl/chat2verbose.pl Fri Dec 13 18:52:49 1991
- ***************
- *** 221,226 ****
- --- 221,227 ----
- $nread = sysread(S, $thisbuf, 1024);
- if ($nread > 0) {
- $S .= $thisbuf;
- + printf STDERR "%s", $thisbuf;
- } else {
- $eof++, redo LOOP; # any error is also eof
- }
-
- which just helps to produce a record on STDERR of the entire session.
-
- Anyway, the important part about the script is that it doesn't send the next
- command until it gets the ftp prompt back, so after a put, it will be safe
- to delete the file (assuming it transfered ok, but that's another story! 8*).
-
- An example script would be:
- ---------------
- open src.doc.ic.ac.uk
- cd gnu
- bin
- get perl-4.035.tar.Z
- quit
- ---------------
-
- Update $name and $password accordingly, though it is unwise to do this for
- non-anonymous ftp!...
-
- Changing the script for your purposes should be fairly straight-forward.
-
- Mark
-
- #!/usr/local/bin/perl
-
- require 'chat2verbose.pl';
-
- $SCRIPT = shift || "ftp.script";
- open(SCRIPT) || die "Can't open $SCRIPT: $!\n";
- @messages = <SCRIPT>;
- close(SCRIPT);
-
- $handle = &chat'open_proc("/usr/ucb/ftp");
-
- $count = 0;
- $name = "anonymous\n";
- $password = "bush@comlab.ox.ac.uk\n"; # My e-mail address
-
- while (1)
- {
- &chat'expect($handle, 2,
- 'EOF', '&chat\'close($handle); exit;',
- '^Name.*$', '&chat\'print($handle, $name)',
- '^ftp\n', '',
- '^Password.*$', '&chat\'print($handle, $password)',
- '^\n', '',
- '^ftp> $', '&sendinfo',
- '^.+\n', '',
- '^.+$', ''
- );
- }
-
- sub sendinfo
- {
- &chat'print($handle, $messages[$count++]);
- }
-