user1480041
user1480041

Reputation: 27

NET::FTP put command in perl

I am trying to restore a file to it's original location. After I login to an FTP server, how do I put it to a certain directory. As of now it will be going to the root directory...

    $f = Net::FTP->new($server, Debug => 0);
    $f->login($username, $passwd) or &fail;
    $msg = "".$f->message."";
    $f->binary();
    $f->put($newfile) or &fail;
    &pass;

Upvotes: 2

Views: 2278

Answers (1)

chipschipschips
chipschipschips

Reputation: 274

Try changing directory first:

$f->cwd('/somedirectory') 
    or die "Cannot change working directory ", $ftp->message;

From the documentation:

cwd ( [ DIR ] )

Attempt to change directory to the directory given in $dir.  If
$dir is "..", the FTP "CDUP" command is used to attempt to move up
one directory. If no directory is given then an attempt is made to
change the directory to the root directory.

Upvotes: 3

Related Questions