Perl Net::FTP::Recursive: Can't download folder but files of subfolders









up vote
0
down vote

favorite












I succeed to download files from a subfolder of the ftp-server. But if I want to download the folders from upper level it does not work.



Here is the folder structure:



  • folder rwx r-x r-x

    • subfolder1 rwx r-x r-x

      • file1 rw- r-- r--

      • file2 rw- r-- r--


    • subfolder2 rxx r-x r-x

      • file3 rw- r-- r--

      • file4 rw- r-- r--



If I use this:



$f1->cwd("/folder/subfolder1");
$f1->rget();
$f1->quit;


the files file1 and file2 will be downloaded.



If I use this:



$f1->cwd("/folder");
$f1->rget();
$f1->quit;


nothing will be downloaded and the program finished due to timeout. I expected that it will download subfolder1 and subfolder2 and the content of the subfolders. Is there any explanation for this and how can I solve it in the way that I can download subfolder and files?



A detailled description of the code is here



UPDATE 1: Debugging



Debugging with



my $f1 = Net::FTP::Recursive->new($host1, Debug => 1) or die "Can't open $host1n";


gives the following:



Net::FTP::Recursive=GLOB(0x312bf50)>>> CWD /folder
Net::FTP::Recursive=GLOB(0x312bf50)<<< 250 CWD command successful
Net::FTP::Recursive=GLOB(0x312bf50)>>> PWD
Net::FTP::Recursive=GLOB(0x312bf50)<<< 257 "/folder" is the current directory
Net::FTP::Recursive=GLOB(0x312bf50)>>> PASV
Net::FTP::Recursive=GLOB(0x312bf50)<<< 227 Entering Passive Mode (188,40,220,103,255,187).
Net::FTP::Recursive=GLOB(0x312bf50)>>> LIST
Net::FTP::Recursive=GLOB(0x312bf50)<<< 150 Opening BINARY mode data connection for file list
Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.


UPDATE 2: Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.



_list_cmd is the function of the line mentioned in the debug output. I also add the lines where _list_cmdis used and wrapped lines to make it more readible conserving line numbers.



 671 # Try to delete the contents
672 # Get a list of all the files in the directory, excluding
# the current and parent directories
673 my @filelist = map /^(?:S+;)+ (.+)$/ ? ($1) : ()
grep !/^(?:S+;)*type=[cp]dir;/i $ftp->_list_cmd("MLSD", $dir);

925 sub ls shift->_list_cmd("NLST", @_);
925 sub dir shift->_list_cmd("LIST", @_);


1087 sub _list_cmd
1088 my $ftp = shift;
1089 my $cmd = uc shift;
1090
1091 delete $*$ftp'net_ftp_port';
1092 delete $*$ftp'net_ftp_pasv';
1093
1094 my $data = $ftp->_data_cmd($cmd, @_);
1095
1096 return
1097 unless (defined $data);
1098
1099 require Net::FTP::A;
1100 bless $data, "Net::FTP::A"; # Force ASCII mode
1101
1102 my $databuf = '';
1103 my $buf = '';
1104 my $blksize = $*$ftp'net_ftp_blksize';
1105
1106 while ($data->read($databuf, $blksize))
1107 $buf .= $databuf;
1108
1109
1110 my $list = [split(/n/, $buf)];
1111
1112 $data->close();
1114 if (EBCDIC)
1115 for (@$list) $_ = $ftp->toebcdic($_)
1116
1117
1118 wantarray
1119 ? @$list
1120 : $list;
1121









share|improve this question



















  • 1




    You might use the Debug option for new to see what it is actually doing. Maybe this will help to debug the problem.
    – Steffen Ullrich
    Nov 10 at 13:20










  • @Steffen I used my $f1 = Net::FTP::Recursive->new($host1, DEBUG => 1) or die "Can't open $f1 $host1n"; and it gives no output. Do you have another debug option?
    – giordano
    Nov 10 at 13:27






  • 2




    It is Debug, not DEBUG. See also the usage example in the documentation.
    – Steffen Ullrich
    Nov 10 at 13:35











  • @Steffen Thanks, I added debug infos in my question.
    – giordano
    Nov 10 at 13:59






  • 2




    Based on the debug output it looks like the server will not reply in time when doing a listing for /folder. Given that it works for /folder/subfolder1 it looks like a server side problem and not a problem of Net::FTP::Recursive.
    – Steffen Ullrich
    Nov 10 at 14:19















up vote
0
down vote

favorite












I succeed to download files from a subfolder of the ftp-server. But if I want to download the folders from upper level it does not work.



Here is the folder structure:



  • folder rwx r-x r-x

    • subfolder1 rwx r-x r-x

      • file1 rw- r-- r--

      • file2 rw- r-- r--


    • subfolder2 rxx r-x r-x

      • file3 rw- r-- r--

      • file4 rw- r-- r--



If I use this:



$f1->cwd("/folder/subfolder1");
$f1->rget();
$f1->quit;


the files file1 and file2 will be downloaded.



If I use this:



$f1->cwd("/folder");
$f1->rget();
$f1->quit;


nothing will be downloaded and the program finished due to timeout. I expected that it will download subfolder1 and subfolder2 and the content of the subfolders. Is there any explanation for this and how can I solve it in the way that I can download subfolder and files?



A detailled description of the code is here



UPDATE 1: Debugging



Debugging with



my $f1 = Net::FTP::Recursive->new($host1, Debug => 1) or die "Can't open $host1n";


gives the following:



Net::FTP::Recursive=GLOB(0x312bf50)>>> CWD /folder
Net::FTP::Recursive=GLOB(0x312bf50)<<< 250 CWD command successful
Net::FTP::Recursive=GLOB(0x312bf50)>>> PWD
Net::FTP::Recursive=GLOB(0x312bf50)<<< 257 "/folder" is the current directory
Net::FTP::Recursive=GLOB(0x312bf50)>>> PASV
Net::FTP::Recursive=GLOB(0x312bf50)<<< 227 Entering Passive Mode (188,40,220,103,255,187).
Net::FTP::Recursive=GLOB(0x312bf50)>>> LIST
Net::FTP::Recursive=GLOB(0x312bf50)<<< 150 Opening BINARY mode data connection for file list
Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.


UPDATE 2: Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.



_list_cmd is the function of the line mentioned in the debug output. I also add the lines where _list_cmdis used and wrapped lines to make it more readible conserving line numbers.



 671 # Try to delete the contents
672 # Get a list of all the files in the directory, excluding
# the current and parent directories
673 my @filelist = map /^(?:S+;)+ (.+)$/ ? ($1) : ()
grep !/^(?:S+;)*type=[cp]dir;/i $ftp->_list_cmd("MLSD", $dir);

925 sub ls shift->_list_cmd("NLST", @_);
925 sub dir shift->_list_cmd("LIST", @_);


1087 sub _list_cmd
1088 my $ftp = shift;
1089 my $cmd = uc shift;
1090
1091 delete $*$ftp'net_ftp_port';
1092 delete $*$ftp'net_ftp_pasv';
1093
1094 my $data = $ftp->_data_cmd($cmd, @_);
1095
1096 return
1097 unless (defined $data);
1098
1099 require Net::FTP::A;
1100 bless $data, "Net::FTP::A"; # Force ASCII mode
1101
1102 my $databuf = '';
1103 my $buf = '';
1104 my $blksize = $*$ftp'net_ftp_blksize';
1105
1106 while ($data->read($databuf, $blksize))
1107 $buf .= $databuf;
1108
1109
1110 my $list = [split(/n/, $buf)];
1111
1112 $data->close();
1114 if (EBCDIC)
1115 for (@$list) $_ = $ftp->toebcdic($_)
1116
1117
1118 wantarray
1119 ? @$list
1120 : $list;
1121









share|improve this question



















  • 1




    You might use the Debug option for new to see what it is actually doing. Maybe this will help to debug the problem.
    – Steffen Ullrich
    Nov 10 at 13:20










  • @Steffen I used my $f1 = Net::FTP::Recursive->new($host1, DEBUG => 1) or die "Can't open $f1 $host1n"; and it gives no output. Do you have another debug option?
    – giordano
    Nov 10 at 13:27






  • 2




    It is Debug, not DEBUG. See also the usage example in the documentation.
    – Steffen Ullrich
    Nov 10 at 13:35











  • @Steffen Thanks, I added debug infos in my question.
    – giordano
    Nov 10 at 13:59






  • 2




    Based on the debug output it looks like the server will not reply in time when doing a listing for /folder. Given that it works for /folder/subfolder1 it looks like a server side problem and not a problem of Net::FTP::Recursive.
    – Steffen Ullrich
    Nov 10 at 14:19













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I succeed to download files from a subfolder of the ftp-server. But if I want to download the folders from upper level it does not work.



Here is the folder structure:



  • folder rwx r-x r-x

    • subfolder1 rwx r-x r-x

      • file1 rw- r-- r--

      • file2 rw- r-- r--


    • subfolder2 rxx r-x r-x

      • file3 rw- r-- r--

      • file4 rw- r-- r--



If I use this:



$f1->cwd("/folder/subfolder1");
$f1->rget();
$f1->quit;


the files file1 and file2 will be downloaded.



If I use this:



$f1->cwd("/folder");
$f1->rget();
$f1->quit;


nothing will be downloaded and the program finished due to timeout. I expected that it will download subfolder1 and subfolder2 and the content of the subfolders. Is there any explanation for this and how can I solve it in the way that I can download subfolder and files?



A detailled description of the code is here



UPDATE 1: Debugging



Debugging with



my $f1 = Net::FTP::Recursive->new($host1, Debug => 1) or die "Can't open $host1n";


gives the following:



Net::FTP::Recursive=GLOB(0x312bf50)>>> CWD /folder
Net::FTP::Recursive=GLOB(0x312bf50)<<< 250 CWD command successful
Net::FTP::Recursive=GLOB(0x312bf50)>>> PWD
Net::FTP::Recursive=GLOB(0x312bf50)<<< 257 "/folder" is the current directory
Net::FTP::Recursive=GLOB(0x312bf50)>>> PASV
Net::FTP::Recursive=GLOB(0x312bf50)<<< 227 Entering Passive Mode (188,40,220,103,255,187).
Net::FTP::Recursive=GLOB(0x312bf50)>>> LIST
Net::FTP::Recursive=GLOB(0x312bf50)<<< 150 Opening BINARY mode data connection for file list
Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.


UPDATE 2: Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.



_list_cmd is the function of the line mentioned in the debug output. I also add the lines where _list_cmdis used and wrapped lines to make it more readible conserving line numbers.



 671 # Try to delete the contents
672 # Get a list of all the files in the directory, excluding
# the current and parent directories
673 my @filelist = map /^(?:S+;)+ (.+)$/ ? ($1) : ()
grep !/^(?:S+;)*type=[cp]dir;/i $ftp->_list_cmd("MLSD", $dir);

925 sub ls shift->_list_cmd("NLST", @_);
925 sub dir shift->_list_cmd("LIST", @_);


1087 sub _list_cmd
1088 my $ftp = shift;
1089 my $cmd = uc shift;
1090
1091 delete $*$ftp'net_ftp_port';
1092 delete $*$ftp'net_ftp_pasv';
1093
1094 my $data = $ftp->_data_cmd($cmd, @_);
1095
1096 return
1097 unless (defined $data);
1098
1099 require Net::FTP::A;
1100 bless $data, "Net::FTP::A"; # Force ASCII mode
1101
1102 my $databuf = '';
1103 my $buf = '';
1104 my $blksize = $*$ftp'net_ftp_blksize';
1105
1106 while ($data->read($databuf, $blksize))
1107 $buf .= $databuf;
1108
1109
1110 my $list = [split(/n/, $buf)];
1111
1112 $data->close();
1114 if (EBCDIC)
1115 for (@$list) $_ = $ftp->toebcdic($_)
1116
1117
1118 wantarray
1119 ? @$list
1120 : $list;
1121









share|improve this question















I succeed to download files from a subfolder of the ftp-server. But if I want to download the folders from upper level it does not work.



Here is the folder structure:



  • folder rwx r-x r-x

    • subfolder1 rwx r-x r-x

      • file1 rw- r-- r--

      • file2 rw- r-- r--


    • subfolder2 rxx r-x r-x

      • file3 rw- r-- r--

      • file4 rw- r-- r--



If I use this:



$f1->cwd("/folder/subfolder1");
$f1->rget();
$f1->quit;


the files file1 and file2 will be downloaded.



If I use this:



$f1->cwd("/folder");
$f1->rget();
$f1->quit;


nothing will be downloaded and the program finished due to timeout. I expected that it will download subfolder1 and subfolder2 and the content of the subfolders. Is there any explanation for this and how can I solve it in the way that I can download subfolder and files?



A detailled description of the code is here



UPDATE 1: Debugging



Debugging with



my $f1 = Net::FTP::Recursive->new($host1, Debug => 1) or die "Can't open $host1n";


gives the following:



Net::FTP::Recursive=GLOB(0x312bf50)>>> CWD /folder
Net::FTP::Recursive=GLOB(0x312bf50)<<< 250 CWD command successful
Net::FTP::Recursive=GLOB(0x312bf50)>>> PWD
Net::FTP::Recursive=GLOB(0x312bf50)<<< 257 "/folder" is the current directory
Net::FTP::Recursive=GLOB(0x312bf50)>>> PASV
Net::FTP::Recursive=GLOB(0x312bf50)<<< 227 Entering Passive Mode (188,40,220,103,255,187).
Net::FTP::Recursive=GLOB(0x312bf50)>>> LIST
Net::FTP::Recursive=GLOB(0x312bf50)<<< 150 Opening BINARY mode data connection for file list
Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.


UPDATE 2: Timeout at C:/Strawberry/perl/lib/Net/FTP.pm line 1107.



_list_cmd is the function of the line mentioned in the debug output. I also add the lines where _list_cmdis used and wrapped lines to make it more readible conserving line numbers.



 671 # Try to delete the contents
672 # Get a list of all the files in the directory, excluding
# the current and parent directories
673 my @filelist = map /^(?:S+;)+ (.+)$/ ? ($1) : ()
grep !/^(?:S+;)*type=[cp]dir;/i $ftp->_list_cmd("MLSD", $dir);

925 sub ls shift->_list_cmd("NLST", @_);
925 sub dir shift->_list_cmd("LIST", @_);


1087 sub _list_cmd
1088 my $ftp = shift;
1089 my $cmd = uc shift;
1090
1091 delete $*$ftp'net_ftp_port';
1092 delete $*$ftp'net_ftp_pasv';
1093
1094 my $data = $ftp->_data_cmd($cmd, @_);
1095
1096 return
1097 unless (defined $data);
1098
1099 require Net::FTP::A;
1100 bless $data, "Net::FTP::A"; # Force ASCII mode
1101
1102 my $databuf = '';
1103 my $buf = '';
1104 my $blksize = $*$ftp'net_ftp_blksize';
1105
1106 while ($data->read($databuf, $blksize))
1107 $buf .= $databuf;
1108
1109
1110 my $list = [split(/n/, $buf)];
1111
1112 $data->close();
1114 if (EBCDIC)
1115 for (@$list) $_ = $ftp->toebcdic($_)
1116
1117
1118 wantarray
1119 ? @$list
1120 : $list;
1121






perl ftp net-ftp






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked Nov 10 at 11:41









giordano

96421533




96421533







  • 1




    You might use the Debug option for new to see what it is actually doing. Maybe this will help to debug the problem.
    – Steffen Ullrich
    Nov 10 at 13:20










  • @Steffen I used my $f1 = Net::FTP::Recursive->new($host1, DEBUG => 1) or die "Can't open $f1 $host1n"; and it gives no output. Do you have another debug option?
    – giordano
    Nov 10 at 13:27






  • 2




    It is Debug, not DEBUG. See also the usage example in the documentation.
    – Steffen Ullrich
    Nov 10 at 13:35











  • @Steffen Thanks, I added debug infos in my question.
    – giordano
    Nov 10 at 13:59






  • 2




    Based on the debug output it looks like the server will not reply in time when doing a listing for /folder. Given that it works for /folder/subfolder1 it looks like a server side problem and not a problem of Net::FTP::Recursive.
    – Steffen Ullrich
    Nov 10 at 14:19













  • 1




    You might use the Debug option for new to see what it is actually doing. Maybe this will help to debug the problem.
    – Steffen Ullrich
    Nov 10 at 13:20










  • @Steffen I used my $f1 = Net::FTP::Recursive->new($host1, DEBUG => 1) or die "Can't open $f1 $host1n"; and it gives no output. Do you have another debug option?
    – giordano
    Nov 10 at 13:27






  • 2




    It is Debug, not DEBUG. See also the usage example in the documentation.
    – Steffen Ullrich
    Nov 10 at 13:35











  • @Steffen Thanks, I added debug infos in my question.
    – giordano
    Nov 10 at 13:59






  • 2




    Based on the debug output it looks like the server will not reply in time when doing a listing for /folder. Given that it works for /folder/subfolder1 it looks like a server side problem and not a problem of Net::FTP::Recursive.
    – Steffen Ullrich
    Nov 10 at 14:19








1




1




You might use the Debug option for new to see what it is actually doing. Maybe this will help to debug the problem.
– Steffen Ullrich
Nov 10 at 13:20




You might use the Debug option for new to see what it is actually doing. Maybe this will help to debug the problem.
– Steffen Ullrich
Nov 10 at 13:20












@Steffen I used my $f1 = Net::FTP::Recursive->new($host1, DEBUG => 1) or die "Can't open $f1 $host1n"; and it gives no output. Do you have another debug option?
– giordano
Nov 10 at 13:27




@Steffen I used my $f1 = Net::FTP::Recursive->new($host1, DEBUG => 1) or die "Can't open $f1 $host1n"; and it gives no output. Do you have another debug option?
– giordano
Nov 10 at 13:27




2




2




It is Debug, not DEBUG. See also the usage example in the documentation.
– Steffen Ullrich
Nov 10 at 13:35





It is Debug, not DEBUG. See also the usage example in the documentation.
– Steffen Ullrich
Nov 10 at 13:35













@Steffen Thanks, I added debug infos in my question.
– giordano
Nov 10 at 13:59




@Steffen Thanks, I added debug infos in my question.
– giordano
Nov 10 at 13:59




2




2




Based on the debug output it looks like the server will not reply in time when doing a listing for /folder. Given that it works for /folder/subfolder1 it looks like a server side problem and not a problem of Net::FTP::Recursive.
– Steffen Ullrich
Nov 10 at 14:19





Based on the debug output it looks like the server will not reply in time when doing a listing for /folder. Given that it works for /folder/subfolder1 it looks like a server side problem and not a problem of Net::FTP::Recursive.
– Steffen Ullrich
Nov 10 at 14:19













1 Answer
1






active

oldest

votes

















up vote
0
down vote













To download the directories and files a tried the following workaround: using a loop over all subdirectory and appyling rget. It does the job I want. Nevertheless, the reason why rget does not work on the upper level is still not answered. At least now it is clear that it is not a permission probplem.



# ftp-server directory
my $ftpdir = "folder";

# Defie local download folder
my $download = "C:/local";
chdir($download);

# Change to remote directory
$f1->cwd($ftpdir) or die "Can't cwd to $ftpdirn", $f1->message;

# grep all folder of top level
my @ftp_directories = $f1->ls;

# remove . and ..
@ftp_subdir = grep ! /^.+$/, @ftp_subdir;

foreach my $sd (@ftp_subdir)

# Make folder on local computer
my $localdir = catfile($download,$sd);
mkdir $localdir;

# Change local working directory
chdir $localdir;


# Change to remote sub directory to be downloaded
$f1->cwd($sd) or die "Can't cwd to $sdn";


# download files
$f1->rget();

# Change to upper level
$f1->cwd("..");
}

$f1->quit;





share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238575%2fperl-netftprecursive-cant-download-folder-but-files-of-subfolders%23new-answer', 'question_page');

    );

    Post as a guest






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    To download the directories and files a tried the following workaround: using a loop over all subdirectory and appyling rget. It does the job I want. Nevertheless, the reason why rget does not work on the upper level is still not answered. At least now it is clear that it is not a permission probplem.



    # ftp-server directory
    my $ftpdir = "folder";

    # Defie local download folder
    my $download = "C:/local";
    chdir($download);

    # Change to remote directory
    $f1->cwd($ftpdir) or die "Can't cwd to $ftpdirn", $f1->message;

    # grep all folder of top level
    my @ftp_directories = $f1->ls;

    # remove . and ..
    @ftp_subdir = grep ! /^.+$/, @ftp_subdir;

    foreach my $sd (@ftp_subdir)

    # Make folder on local computer
    my $localdir = catfile($download,$sd);
    mkdir $localdir;

    # Change local working directory
    chdir $localdir;


    # Change to remote sub directory to be downloaded
    $f1->cwd($sd) or die "Can't cwd to $sdn";


    # download files
    $f1->rget();

    # Change to upper level
    $f1->cwd("..");
    }

    $f1->quit;





    share|improve this answer
























      up vote
      0
      down vote













      To download the directories and files a tried the following workaround: using a loop over all subdirectory and appyling rget. It does the job I want. Nevertheless, the reason why rget does not work on the upper level is still not answered. At least now it is clear that it is not a permission probplem.



      # ftp-server directory
      my $ftpdir = "folder";

      # Defie local download folder
      my $download = "C:/local";
      chdir($download);

      # Change to remote directory
      $f1->cwd($ftpdir) or die "Can't cwd to $ftpdirn", $f1->message;

      # grep all folder of top level
      my @ftp_directories = $f1->ls;

      # remove . and ..
      @ftp_subdir = grep ! /^.+$/, @ftp_subdir;

      foreach my $sd (@ftp_subdir)

      # Make folder on local computer
      my $localdir = catfile($download,$sd);
      mkdir $localdir;

      # Change local working directory
      chdir $localdir;


      # Change to remote sub directory to be downloaded
      $f1->cwd($sd) or die "Can't cwd to $sdn";


      # download files
      $f1->rget();

      # Change to upper level
      $f1->cwd("..");
      }

      $f1->quit;





      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        To download the directories and files a tried the following workaround: using a loop over all subdirectory and appyling rget. It does the job I want. Nevertheless, the reason why rget does not work on the upper level is still not answered. At least now it is clear that it is not a permission probplem.



        # ftp-server directory
        my $ftpdir = "folder";

        # Defie local download folder
        my $download = "C:/local";
        chdir($download);

        # Change to remote directory
        $f1->cwd($ftpdir) or die "Can't cwd to $ftpdirn", $f1->message;

        # grep all folder of top level
        my @ftp_directories = $f1->ls;

        # remove . and ..
        @ftp_subdir = grep ! /^.+$/, @ftp_subdir;

        foreach my $sd (@ftp_subdir)

        # Make folder on local computer
        my $localdir = catfile($download,$sd);
        mkdir $localdir;

        # Change local working directory
        chdir $localdir;


        # Change to remote sub directory to be downloaded
        $f1->cwd($sd) or die "Can't cwd to $sdn";


        # download files
        $f1->rget();

        # Change to upper level
        $f1->cwd("..");
        }

        $f1->quit;





        share|improve this answer












        To download the directories and files a tried the following workaround: using a loop over all subdirectory and appyling rget. It does the job I want. Nevertheless, the reason why rget does not work on the upper level is still not answered. At least now it is clear that it is not a permission probplem.



        # ftp-server directory
        my $ftpdir = "folder";

        # Defie local download folder
        my $download = "C:/local";
        chdir($download);

        # Change to remote directory
        $f1->cwd($ftpdir) or die "Can't cwd to $ftpdirn", $f1->message;

        # grep all folder of top level
        my @ftp_directories = $f1->ls;

        # remove . and ..
        @ftp_subdir = grep ! /^.+$/, @ftp_subdir;

        foreach my $sd (@ftp_subdir)

        # Make folder on local computer
        my $localdir = catfile($download,$sd);
        mkdir $localdir;

        # Change local working directory
        chdir $localdir;


        # Change to remote sub directory to be downloaded
        $f1->cwd($sd) or die "Can't cwd to $sdn";


        # download files
        $f1->rget();

        # Change to upper level
        $f1->cwd("..");
        }

        $f1->quit;






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 6 hours ago









        giordano

        96421533




        96421533



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53238575%2fperl-netftprecursive-cant-download-folder-but-files-of-subfolders%23new-answer', 'question_page');

            );

            Post as a guest














































































            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            Node.js Script on GitHub Pages or Amazon S3

            Museum of Modern and Contemporary Art of Trento and Rovereto