any2xml has asked for the wisdom of the Perl Monks concerning the following question:

I need to be able to intercept the FTP responses from the server. Here I am ringing the bells at the gate! I use Net::FTP to send a job to OS/390. This is done by using the site command "SITE FILETYPE=JES". This opens a pipe to the job scheduler (JES) on the mainframe and the STORed file is interpreted as job. No problem. Everything works fine. In face I use MVS::JESFTP by Mike Owens. When the job is submitted via the STOR, the OS/390 ftp server responds with a job number, which I can use to track output, since there can be many jobs with the same name. My problem is I am not able to catch the responses from the OS/390. Command line client FTP shows the following trail.. Notice the "JOB23077" below? I need to parse it out.
ftp> site filetype=jes
200 SITE command was accepted
ftp> put TEST.SEQ3
local: TEST.SEQ3 remote: TEST.SEQ3
500 unknown command EPSV
227 Entering Passive Mode (167,184,25,2,14,143)
125 Sending Job to JES internal reader FIXrecfm 80 100%
|*********************| 875 1.69 MB/s --:-- ETA
250-It is known to JES as JOB23077
250 Transfer completed successfully.

Replies are listed 'Best First'.
Re: How to get FTP log via Net::FTP
by Roger (Parson) on Dec 31, 2003 at 05:17 UTC
    You could turn on Net::FTP debugging:
    my $ftp = Net::FTP->new($HOST, Debug => 1);
    And then use the Net::Cmd debugging methods (such as message) to retrieve the returned messages from the FTP server. Read the documentation of Net::Cmd on CPAN for a list of debugging facilities/methods available.

      That was quick. I checked Net::FTP to find that there is a message method to return the ftp server response. This method is inherited by MVS::JESFTP. It gave me what I wanted. Thank you so much. For those who use MVS::JESFTP, after every FTP command you can use MVS::JESFTP->message (or say $jes->message where $jes is the object) which returns an array of lines. Currently MVS::JESFTP checks held output for jobname. It can be easily modified to check on jobnumber, which is more accurate. Happy New Year all!!
Re: How to get FTP log via Net::FTP
by delirium (Chaplain) on Dec 31, 2003 at 13:23 UTC
    The Debug=>1 option dumps messages wholesale to STDERR. For what it's worth, something like this will give you the whole session log as a scalar:

    use IO::Scalar; my $stderr; tie *STDERR, 'IO::Scalar', \$stderr; my ($address, $timeout, $port) = ('127.0.0.1', 90, 21); my $ftp=Net::FTP->new($address, Timeout=>$timeout, Port=>$port, Debug= +>1); ## do ftp stuff.. if ($stderr) { $stderr =~ s/Net::FTP.+?\(.+?\)\n?//g; # Trim off Debug header, s +ave meat $stderr =~ s/\n+/\n/g; # Get rid of blank lines open LOG, '>>', 'some_logfile'; flock LOG, 2; print LOG "$stderr\n"; close LOG; }

    The scalar $stderr can be manipulated to create a commented log as you go. e.g.:
    $stderr.="Trying to download the file\n"; $ftp->get(...);