diff options
author | Steve Hay <steve.m.hay@googlemail.com> | 2015-07-17 09:30:45 +0100 |
---|---|---|
committer | Steve Hay <steve.m.hay@googlemail.com> | 2015-07-17 09:30:45 +0100 |
commit | 0f8f4ed9c78b48a7f75d723534b65e7a1b0d33be (patch) | |
tree | ac7d8a705023944415f119380f9a365432775be5 | |
parent | f418673741da4fad729da4bc2d3d53ca8e7f3c80 (diff) | |
parent | c70379798581f1e642bfdff9af1acb55dfc1a37c (diff) | |
download | perl-libnet-0f8f4ed9c78b48a7f75d723534b65e7a1b0d33be.tar.gz |
Merge branch 'ColMelvin-use-MLSD-for-more-robustness'
-rw-r--r-- | lib/Net/FTP.pm | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/lib/Net/FTP.pm b/lib/Net/FTP.pm index 9278589..7700bb3 100644 --- a/lib/Net/FTP.pm +++ b/lib/Net/FTP.pm @@ -669,8 +669,12 @@ sub rmdir { or !$recurse; # Try to delete the contents - # Get a list of all the files in the directory - my @filelist = grep { !/^\.{1,2}$/ } $ftp->ls($dir); + # Get a list of all the files in the directory, excluding the current and parent directories + my @filelist = map { /^(?:\S+;)+ (.+)$/ ? ($1) : () } grep { !/^(?:\S+;)*type=[cp]dir;/ } $ftp->_list_cmd("MLSD", $dir); + + # Fallback to using the less well-defined NLST command if MLSD fails + @filelist = grep { !/^\.{1,2}$/ } $ftp->ls($dir) + unless @filelist; return unless @filelist; # failed, it is probably not a directory @@ -1151,7 +1155,7 @@ sub _data_cmd { my $data = $ftp->_dataconn(); if (CMD_INFO == $ftp->response()) { $data->reading - if $data && $cmd =~ /RETR|LIST|NLST/; + if $data && $cmd =~ /RETR|LIST|NLST|MLSD/; return $data; } $data->_close if $data; @@ -1190,7 +1194,7 @@ sub _data_cmd { my $data = $ftp->_dataconn(); $data->reading - if $data && $cmd =~ /RETR|LIST|NLST/; + if $data && $cmd =~ /RETR|LIST|NLST|MLSD/; return $data; } |