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

Hi,Can Net::FTP upload folders instead of files to the ftp server. I want to upload folder to ftp server. How can i do that?

Replies are listed 'Best First'.
Re: upload folder to ftp server
by MidLifeXis (Monsignor) on Jun 25, 2009 at 14:50 UTC

    Look at Net::FTP::Recursive. I have not personally used it, so I cannot vouch for its correctness.

    --MidLifeXis

    The tomes, scrolls etc are dusty because they reside in a dusty old house, not because they're unused. --hangon in this post

Re: upload folder to ftp server
by Khen1950fx (Canon) on Jun 25, 2009 at 20:08 UTC
    I've had good results with Net::FTP::Robust; however, most of the ftp servers that I use are set up to retrieve or accept files only. You'll see "I can only retrieve regular files" in this script:

    #!/usr/bin/perl use strict; use warnings; use Net::FTP::Robust; use Log::Report; use constant HOST => 'ftp.perl.org'; use constant DIR => '/pub/CPAN'; use constant FILE => 'README'; my $ftp = Net::FTP->new(HOST, Debug => 1, Passive => 1) or die "Couldn't connect: $@\n"; $ftp->login('anonymous'); $ftp->cwd(DIR); $ftp->get(DIR); try { "error" }; if($@) { '../CPAN' } $ftp->quit;

    Update: You can dramatically speed up file transfer by using Net::FTP::Throttle
    Try this:

    #!/usr/bin/perl use strict; use warnings; use Net::FTP::Robust; use Net::FTP::Throttle; use Log::Report; use constant HOST => 'ftp.perl.org'; use constant DIR => '/pub/CPAN'; use constant FILE => 'README'; my $ftp = Net::FTP->new(HOST, Debug => 1, Passive => 1, MegabitsPerSecond => 2) or die "Couldn't connect: $@\n"; $ftp->login('anonymous'); $ftp->cwd(DIR); $ftp->get(FILE); try { "error" }; if($@) { '../CPAN' } $ftp->quit;
Re: upload folder to ftp server
by Anonymous Monk on Jun 25, 2009 at 14:10 UTC
    make a function to create a directory(mkdir) and put all files in the server, if you found another directory just call this same function.
      Thanks for the reply and if that folder contains subfolder then it is very length process. That's y i am checking for any folder upload concept is there? From this we no need to worry about sub folders? right?

        ftp has no concept of folder upload. You will need to write that program yourself.