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

Net::FTP::Recursive question

by sivak1976 (Novice)
on Jul 31, 2007 at 16:50 UTC ( #629867=perlquestion: print w/replies, xml ) Need Help??

sivak1976 has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use Net::FTP::Recursive to unzip an Archive file (.zip) and recursively transfer the directory created to an FTP server. The problem is that my code gives no error messages but the directory is not transferred. The user I am running this program as is able to create directories when using interactive FTP. Also, my code that uses the rget() method of the same module works just fine. It's just that I cannot get the rput() method to work. Code is below. Thanks in advance, sivak1976
#!/usr/bin/perl # Program to recursively put a directory on to an FTP server # after unzipping a Zip file. use strict; use warnings; use Net::FTP::Recursive; use Archive::Zip; # FTP host server my $host = ''; my $zip_file_to_put = ''; # Get the zip archive. my $zip_file_obj = Archive::Zip->new($zip_file_to_put) or die("Could not get zip file: $!"); # Extract the zip files. $zip_file_obj->extractTree(); chdir('ABC') or die("Could not change directory: $!"); # my $current_dir = `pwd`; # print $current_dir, "\n"; my $ftp_obj = Net::FTP::Recursive->new($host, Passive => 1) or die "Cannot connect to $host: $!" ; # Log in to the FTP server. $ftp_obj->login('username', 'password') or die "Cannot log in to $host +: $!" , $ftp_obj->message(); # Go into binary mode for the transfer my $type = $ftp_obj->binary(); # Put the directory in a recursive fashion. my $output = $ftp_obj->rput(); # Print the error messages if the recursive put failed. if($output) { print qq<rput failed, \$output was:\n$output>; } # Quit! $ftp_obj->quit();

Replies are listed 'Best First'.
Re: Net::FTP::Recursive question
by snoopy (Curate) on Aug 01, 2007 at 00:33 UTC
    Are you running on Windows? There's an active bug report on Net::FTP::Recursive 2.00, raised on June 22.

    "Net::FTP::Recursive uses by default the 'ls' command to list directories.

    This obviously won't work if that command isn't available, or is not in the path (such as on Windows). Also, it can cause issues if the module is used with Perl's taint checking turned on."

    If so, you may want to email the author. In the interim, you could work around it in your rput call:
    # Put the directory in a recursive fashion. my $output = $ftp_obj->rput( Command => '', ParseSub => sub { # code to get files # in current working directory }, );
      I am running on Linux so the "ls" command is available. Also, there is no error message warning me of anything. If I run the program on Windows, I get an error message.

        I think that is exactly soopy's point. If you are running the script on a Linux machine, you will not have the error because "ls" is the usual command for listing directory contents.

        The "ls" command does not exist on a Windows machine. So the error occurs.

        Or are you are running your script from a Linux machine and trying to recursively put to a Windows machine? Doesn't matter... it still won't work because the "ls" command on the Windows box will fail. It doesn't exist.

        Hmmm. Your code works for me under Linux. Some other suggestions:

      • It's not just that the files ending up where you expect? The contents of ABC are going to the home directory. If your intention is to replicate ABC directory. You'll need to create it and cd to it yourself:
        $ftp_obj->mkdir('ABC'); # make sure the directory exists $ftp_obj->cwd('ABC') || die $ftp_obj->message;;
      • Set Debug => 1 when you open the ftp object. It'll give you lots of useful debugging info.

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://629867]
Approved by Corion
Front-paged by Corion
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2022-01-21 22:53 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (59 votes). Check out past polls.