MadraghRua has asked for the wisdom of the Perl Monks concerning the following question:
I want to run a script in a verbose mode to collect lots of information at each step of an ftp session. For each step in the FTP process I want to print a message to standard output. A truncated example is included below.
When I try to do this, the script executes with no errors but I don't know what is actually happening during each step of the ftp process - the standard output does not appear to be there for you to see or collect.
Does Net::FTP open up a seperate shell and run the ftp session through this? This might explain why I cannot capture the standard output from the ftp session from each step of the subroutine.
Should we be using Net::Cmd to capture these responses? Looking at the documentation there is mention of a series of six subroutines: CMD_INFO, CMD_OK, CMD_MORE, CMD_REJECT and CMD_ERROR ,correspond to possible results of response and status. The sixth is CMD_PENDING. However I don't see an example of how these might be used. For chuckles and grins I have read through the associated perlmonks messsages, CPAN documentation and man pages on Net::FTP and Net::Cmd and the Perl Cookbook
Finally I did see the Debug flag in the libnet documentation and we are trying this out. But again, does this faithfully pipe back the messages from the ftp server or is it simply the Net::FTP module's interpretation of the server response?
Here is a copy of the contents of a subroutine that we are using here. We have used strict and the -w flag in another portion of our script, so the code does pass with these tests. We do realize that we could have used 'or die' but we planned to do something that would be a wee bit more extensive and suitable to our needs
...omitted for clarity... print "Connecting to $url ... " ; if ($ftp = Net::FTP->new($url)) { $opt_v and print " as $userName ..." ; if ($ftp->login($userName,$password)) { print "\n" ; $opt_v and print "Changing to directory $sourceDir ..." ; if ($ftp->cwd($sourceDir)) { $opt_v and print "Getting $flatFile ... " ; if ($ftp->get($flatFile)) { print "done"; } else { print "failed to get file\n" ; } } else { print "failed to change directory\n" ; } } else { print "failed to login\n" ; } } else { print " connection failed\n" ; } $ftp->quit;
Thanks in advance for the help!
MadraghRua
yet another biologist hacking perl....
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::FTP and standard output
by petral (Curate) on Jan 03, 2002 at 04:29 UTC | |
by WintersMystic (Novice) on Jan 03, 2002 at 09:16 UTC | |
by petral (Curate) on Jan 03, 2002 at 22:55 UTC | |
|
Re: Net::FTP and standard output
by runrig (Abbot) on Jan 03, 2002 at 04:43 UTC | |
by chip (Curate) on Jan 03, 2002 at 05:40 UTC |