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

Dear Monks,

I am having an issue when using the get method of the Net::FTPSSL module.

When I am calling the get method I am doing this:

if ( $ftps->get("$file","$file") ) { $ftps->delete($file); print MYLOG a-time-stamp-func() . " $file was downloaded from host\ +n"; } else { exception handling; }
>

What happens is that in my log the line that gets written is rather munged for each file that gets downloaded. The word downloaded will appear then a portion of the timestamp and then perhaps the file name. When I use the Net::FTP module with the same type of if statement this does not happen, only with the Net::FTPSSL. Reading the module I can see that the get method creates an instance of IO::Handle tied to Net::SSLeay::Handle.

Not really a major issue but a bit of a nuisance. Any thoughts on what might be causing this?

Update:

I just wasn't looking closely enough at this. The file names have \r in them after chomping. When I tail the log it looks munged, doing more or vi on it looks ok but with the ^M's. The tail is excluding everything on the line up to and including the \r.

zow

Replies are listed 'Best First'.
Re: Net::FTPSSL->get() issue
by Khen1950fx (Canon) on Feb 06, 2010 at 04:37 UTC
    For starters, very few servers will allow you to delete; hence, "delete" $ftps->delete($file). Also, if the timestamp is being mangled, that's because, by default, Net::FTPSSL doesn't preserve timestamps. You'll need to add PreserveTimestamp to the new method. Here's what I tried:
    #!/usr/bin/perl use strict; use warnings; use Net::FTPSSL; use constant HOST => 'ftp.perl.org'; use constant DIR => '/pub/CPAN'; use constant REMOTE_FILE => 'README'; use constant LOCAL_FILE => 'README'; my $ftps = Net::FTPSSL->new(HOST, PreserveTimestamp => 1, Port => 21, Debug => 1, Croak => 1, Trace => 1); $ftps->login('user', 'pass'); $ftps->cwd(DIR); if ( $ftps->get(REMOTE_FILE, LOCAL_FILE) ) { open(MYLOG, '>', 'Mylog.txt'); print MYLOG time() . " LOCAL_FILE was downloaded from HOST\n"; } else { print "There was a problem.\n"; } unlink(LOCAL_FILE); $ftps->quit();
    Update: Here's an example using Tie::Scalar::Timestamp
    #!/usr/bin/perl use strict; use warnings; use Net::FTPSSL; use constant HOST => 'ftp.perl.org'; use constant DIR => '/pub/CPAN'; use constant REMOTE_FILE => 'README'; use constant LOCAL_FILE => 'README'; my $ftps = Net::FTPSSL->new(HOST, PreserveTimestamp => 1, Port => 21, Debug => 1, Croak => 1, Trace => 1); $ftps->login('anonymous'); $ftps->cwd(DIR); if ( $ftps->get(REMOTE_FILE, LOCAL_FILE) ) { use Tie::Scalar::Timestamp; $Tie::Scalar::Timestamp::DEFAULT_STRFTIME = '%H:%M:%S'; open(MYLOG, '>', 'Mylog.txt'); tie my $timestamp, 'Tie::Scalar::Timestamp'; print MYLOG $timestamp . " LOCAL_FILE was downloaded from HOST\n"; } else { print "There was a problem.\n"; } unlink(LOCAL_FILE);

      Thanks, I will give that a shot Monday. Trying to set up a FTPS server at home to be able to play with this sort of thing off hours...

      zow