Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Net::FTP Question . . .

Status
Not open for further replies.

youthman

Programmer
Apr 28, 2004
49
0
0
US
I have a script that uploads a series of files from one server to another using Net::FTP. The problem is that many times these files already exist and when they do, the server kicks back a "Do you want to overwrite" option. I am trying to run this automatically, but needless to say these overwrite options stop the rest of the program. My question is: Is there a way to set the options for overwrite inside of the script? Here is a sample of my code!
Code:
    $ftp = Net::FTP->new("hostname", Debug => 0) or die "Cannot connect: $@";

   $ftp->login("login",'password') or die "Cannot login ", $ftp->message;

    $ftp->cwd("public_html/images/full/") or die "Cannot change working directory to full:", $ftp->message;
print "connected getting ready to upload fullsize . . . . ";
  opendir(DIR, "$dirname") or die "can't opendir $dirname: $!";
  while (defined($file = readdir(DIR))) {
    if($file eq ".") {
      next;
    }
    if($file eq "..") {
      next;
    }

    $ftp->put("full/$file") or die "put failed ", $ftp->message;
    $fulls_uploaded++;
    }

Any help would be greatly appreciated!
 
What kind of ftp server are you connecting to? A put *SHOULD* be all that is needed.
[ul]Is this a mainfraime?
[li]you may need to $ftp->quot( "COMMAND HERE" ) to tell the
ftp server to go into overwrite mode (or what ever it is called)[/li]
[li]you may be able to find this out by manually connecting via the console 'ftp' client. Log in and type 'quote site help'[/li]
[/ul]

Otherwise I'd suggest using:
$ftp->delete($file) if $ftp->size($file);
to clean up the file before writing.

Or even putting the file as a different name and then renaming it over the old file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top