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!

Perl FTP Remote Rename problem 1

Status
Not open for further replies.

TheNewbie81

Technical User
Feb 12, 2007
15
IE
Hi,

I am trying to rename files ona remote server using this simple bit of code, but it doesnt work, can anyone point out what im doing wrong?

cheers
Jon

Code:
#!/usr/bin/perl

use Net::FTP;

    $ftp = Net::FTP->new("localhost", Debug => 0);
    $ftp->login("anonymous",'-anonymous@');
    $ftp->cwd("/");
    
    @dir=$ftp->ls or $newerr=1;
  
    foreach $file(@dir){
    
    $ftp->get($file);  
    $ftp->rename( $file, "$file\.recieved")
    or die "Couldn't rename file";

    }
    $ftp->quit;
 
change to
or die "Couldn't rename file: $!\n";

and tell us what the message you get it. I would just guess it's a permissions problem

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
You should probably also specify ascii or binary as different servers seem to default to different settings.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Hi,

im getting this
"Couldn't rename at ftp.pl line 20"

looks like its not picking up the file name??

 
cheers it was permissions!
 
Cool.. Glad you figured it out.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those Who Say It Cannot Be Done Are Usually Interrupted by Someone Else Doing It; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top