in reply to ftp->put file error

After you assemble the file name, you should check to see if it exists.

Suggested code snippet(with comments):

my $localfile = "$csvdir/$astfile"; # No need to "join", and "/" works + fine for windows too. -e $localfile or die "Error: '$localfile' does not exist"; # Existance verified - now we can "put" it
A few more pointers:

     Syntactic sugar causes cancer of the semicolon.        --Alan Perlis

Replies are listed 'Best First'.
Re^2: ftp->put file error
by salatconed (Initiate) on Dec 02, 2010 at 14:52 UTC
    Thanks for the advice, I moved the timestap to the logit() subroutine and put in the test if the file exists. The code is still giving the same error.
    When I run the command manually the program gives the following error:
    Died at c:\FTP_Scripts\xml-ast-convert\xml-ast-convert.pl line 276.
    Liner 276 is the die statement after the ftp->put() call.
    The file exist test is successfull and the log file shows the correct file name and path, am I using the ftp->put() command incorrectly
    #test if ast file exists -e $astfile or die "Error: '$astfile' does not exist"; #open FTP session with remote server $ftp=Net::FTP->new($elutionsFTP, Timeout=>20, Debug=>0, Passive=>1) or $err=1; if($err){ logit("$error_time_stamp >Unable to connect to remote FTP serv +er $elutionsFTP\n$!"); die; } #login to to remote FTP server $ftp->login("$elutionsID", "$elutionsPWD") or $err=1; if($err){ logit("$error_time_stamp > Unable to login to remote FTP server $e +lutionsFTP as $elutionsID\n$!"); die; } #change directory on FTP server $ftp->cwd($putdir) or $err=1; if ($err) { logit("$error_time_stamp > Unable to change directory $putdir on $ +elutionsFTP server\n$!"); die; } $ftp->binary(); # set binary mode $ftp->put($astfile) or $err=1; if ($err) { logit("$error_time_stamp > Error transferring $astfile\n$!"); die ; } # Log successfull upload logit("\n\n$error_time_stamp > Transfer successfull: FTPserver: $eluti +onsFTP\n File: $astfile\n$!"); # End session $ftp->quit(); exit 0;

    Log file output


    Input XML file: c:\FTP_Scripts\xml-ast-convert\FTP_111100409D45C8DD_1201101600_0.xml

    Output directory: c:\FTP_Scripts\xml-ast-convert
    Successfully opened file: c:\FTP_Scripts\xml-ast-convert\FTP_111100409D45C8DD_1201101600_0.xml

    Successfully created file: c:\FTP_Scripts\xml-ast-convert\NYPH-20101101-210000.ast

    Error transferring c:\FTP_Scripts\xml-ast-convert\NYPH-20101101-210000.ast

    Bad file descriptor
      I have tried hard coding the file name and path and get the same results, I have tried the following:
      $astfile = 'c:/FTP_Scripts/xml-ast-convert/NYPH-20101101-210000.ast';
      $astfile = "c:/FTP_Scripts/xml-ast-convert/NYPH-20101101-210000.ast";
      $astfile = 'c:\\FTP_Scripts\\xml-ast-convert\\NYPH-20101101-210000.ast';
      $astfile = 'c:\FTP_Scripts\xml-ast-convert\NYPH-20101101-210000.ast';
      all of these fail the same way
        OK, out of desperation I tested against a different FTP server and that one works fine.
        Is there a different FTP module I could try or can I get a more descriptive error from Net::FTP?
        OK Mistery solved, I was trying to put files into a directory with read only access. Thanks for the help