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

I've written a script that uses net::FTPSSL from unix to windows, to upload a file to make sure ftp is working. It works fine. I was trying to generate an error where the file to upload was not found an instead of emailing me an error, it just printed one to the screen that the file wasn't found. I am trying to check the return code from the ftps but I am very new to this. This statement works if it can't put the file up but not if the file doesn't exist. $ftps->put("/temp/testuploadfile.txt") or emailerr("Error: $0 could upload testftpsfile to FTPS server at IP $ftpsip with FTPS p rotocol.", $ftps->$last_message() ); I was researching and checking debug output and see 226 is a successful put, but I don't know how to check that. How do I check the return code? I was trying to use something like this but it didn't work my $rtncode=$ftps->code; if ($rtncode != 226 && $rtncode != 250) { my $msg=$ftp->message; print "FTP Failed: $msg\n"; $ftp->quit; } OR ###print "error $Net::FTPSSL::ERRSTR"; Any help wourl be appreciated.

Replies are listed 'Best First'.
Re: checking return from Net::FTPSSL
by zentara (Cardinal) on Oct 07, 2015 at 12:44 UTC
    Have you tried the debug option?
    my $ftps = Net::FTPSSL->new($server, Encryption => EXP_CRYPT, Debug => 1, Croak => 1) or die "Can't open $server\n$Net::FTPSSL::ERRSTR";

    I'm not really a human, but I play one on earth.
    Old Perl Programmer Haiku ................... flash japh
      Thank you. Your suggestions were very helpful and some were implemented.
Re: checking return from Net::FTPSSL
by tangent (Parson) on Oct 07, 2015 at 00:43 UTC
    I'm not sure why it is behaving differently if the file doesn't exist - can you show how you create the ftps object?

    You can always check yourself that the file exists before calling put:
    if ( ! -e $file ) { emailerr("$file does not exist"); } else { $ftps->put($file); }
    To check if put() was successful you only need to see if the last FTP status code starts with "2", so:
    my $rtncode = $ftps->last_status_code; if ( $rtncode != 2 ) { # deal with error }
    Note: last_status_code() returns the first digit from the full 3 digit response code.