Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re: Net:FTP Not overwrite files

by Khen1950fx (Canon)
on Jul 26, 2008 at 09:18 UTC ( #700284=note: print w/replies, xml ) Need Help??

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 => ''; 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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://700284]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (8)
As of 2020-02-28 16:11 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (124 votes). Check out past polls.