in reply to Net:FTP Not overwrite files

Using an example from Network Programming with Perl - Ch.6 FTP and Telnet:

#!/usr/bin/perl use strict; use warnings; use Net::FTP::File; use constant HOST => 'ftp.perl.org'; use constant DIR => '/pub/CPAN'; use constant FILE => 'README'; my $ftp = Net::FTP->new(HOST, Debug => 1) or die "Couldn't connect: $@ +\n"; $ftp->login('anonymous'); $ftp->cwd(DIR); $ftp->put(FILE) unless $ftp->isfile(FILE); warn "File exists.\n"; $ftp->quit;

Replies are listed 'Best First'.
Re^2: Net:FTP Not overwrite files
by alexm (Chaplain) on Jul 26, 2008 at 19:26 UTC

    Net-FTP-File has also the exists() method, which would be more appropiate because if the filename exists and is actually a directory the file put through FTP would be created under that directory, which doesn't seem to be the OP's desired behaviour.

      Hi i developed a very simples way to accomplish that it is so simple and work with the old Net::FTP
      $ftp->put("$file") unless $ftp->rename("$file","$file");
      well gonna put file only if it doens't exits otherwise it will rename it with the same actual name! it is genious regards Claudio
        that's a good idea, but mdtm() or size() can be better. because rename() changes its property. mdtm() and size() changes nothing.