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

hello guys!

i just have a simple question about the Net::FTP module. i am using Net::FTP to get files from remote server and i can so that, but i don't know how to store those retrieved files in a specific folder i assigned. I've tried using the "where" option, but i always get response like "cannot open the directory, the directory is not exists" something like that (i did create a that folder).

I'd appreciate any help, thanks in advance.

Replies are listed 'Best First'.
Re: Net::FTP get function question
by Illuminatus (Curate) on Mar 11, 2010 at 20:23 UTC
    The where option is not what you want. Read the module documentation to find out why. The second argument, LOCAL_FILE, should take a full path-name. Since you used the word 'folder', I am assuming you are running the client on windows. Usually, even though you are on windows, you should still use forward-slashes in the path. I think you can still pre-pend the drive letter (ie C:), but am not sure.

    fnord

Re: Net::FTP get function question
by Khen1950fx (Canon) on Mar 11, 2010 at 21:18 UTC
    This is the laziest way that I know. First, create the directory where you want to store the files. Next, cd to that directory. For an example, try this:
    #!/usr/bin/perl use strict; use warnings; use Net::FTP; use constant HOST => 'ftp.cpan.org'; use constant DIR1 => '/pub/CPAN/authors'; use constant FILE1 => '01mailrc.txt.gz'; use constant DIR2 => '/pub/CPAN/modules'; use constant FILE2 => '02packages.details.txt.gz'; use constant FILE3 => '03modlist.data.gz'; my $ftp = Net::FTP->new( HOST, Debug => 1, Passive => 1, Timeout => 1 ); $ftp->login('anonymous'); $ftp->cwd(DIR1); $ftp->binary; $ftp->get(FILE1); $ftp->cwd(DIR2); $ftp->get(FILE2); $ftp->get(FILE3); $ftp->quit;
      thanks! actually, i found a easier way, just as Illuminatus said, in the the second argument, LOCAL_FILE, i just have to indicate the whole path where i want to save the file and append the file name after it, it would work.

      my code: <code> $ftp -> get ($file_name, "/home/xiaoyao/Desktop/updating_files/" . $file_name ) or die "get $file_name failed: " . $ftp -> message() ; <code>

      Thanks any way.