From 5b4b507340d916b8001bd1decc1fadd5fc3496c8 Mon Sep 17 00:00:00 2001 From: Quentin Garnier Date: Fri, 19 Sep 2014 16:44:31 +0200 Subject: [PATCH] Fix #5388 --- apps/protocols/ftp/mode/commands.pm | 2 +- apps/protocols/ftp/mode/date.pm | 10 +++++++--- apps/protocols/ftp/mode/filescount.pm | 19 ++++++++++--------- apps/protocols/ftp/mode/login.pm | 2 +- 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/apps/protocols/ftp/mode/commands.pm b/apps/protocols/ftp/mode/commands.pm index 7c7729d09..471c5ea2d 100644 --- a/apps/protocols/ftp/mode/commands.pm +++ b/apps/protocols/ftp/mode/commands.pm @@ -172,7 +172,7 @@ Need Perl 'Net::FTPSSL' module =item B<--ftp-options> Add custom ftp options. -Example: --ftp-options='Debug=1" --ftp-options='useSSL=1" +Example: --ftp-options='Debug=1" --ftp-options='useSSL=1' =item B<--username> diff --git a/apps/protocols/ftp/mode/date.pm b/apps/protocols/ftp/mode/date.pm index 973fc048f..98ac20520 100644 --- a/apps/protocols/ftp/mode/date.pm +++ b/apps/protocols/ftp/mode/date.pm @@ -98,7 +98,11 @@ sub run { apps::protocols::ftp::lib::ftp::connect($self); my $current_time = time(); - foreach my $dir (@{$self->{option_results}->{directory}}) { + my $dirs = ['.']; + if (defined($self->{option_results}->{directory}) && scalar(@{$self->{option_results}->{directory}}) != 0) { + $dirs = $self->{option_results}->{directory}; + } + foreach my $dir (@$dirs) { my @files; if (!(@files = apps::protocols::ftp::lib::ftp::execute($self, command => $map_commands{ls}->{$self->{ssl_or_not}}->{name}, command_args => [$dir]))) { @@ -113,7 +117,7 @@ sub run { my $time_result; if (!($time_result = apps::protocols::ftp::lib::ftp::execute($self, command => $map_commands{mdtm}->{$self->{ssl_or_not}}->{name}, command_args => [$file]))) { - # Surely a directory. So we go forward. Can't get time for that. + # Sometime we can't have mtime for a directory next; } @@ -184,7 +188,7 @@ Need Perl 'Net::FTPSSL' module =item B<--ftp-options> Add custom ftp options. -Example: --ftp-options='Debug=1" --ftp-options='useSSL=1" +Example: --ftp-options='Debug=1" --ftp-options='useSSL=1' =item B<--username> diff --git a/apps/protocols/ftp/mode/filescount.pm b/apps/protocols/ftp/mode/filescount.pm index 877541ffb..1b6831d1e 100644 --- a/apps/protocols/ftp/mode/filescount.pm +++ b/apps/protocols/ftp/mode/filescount.pm @@ -44,8 +44,7 @@ use File::Basename; # How much arguments i need and commands manages my %map_commands = ( - mdtm => { ssl => { name => '_mdtm' }, nossl => { name => 'mdtm' } }, - ls => { ssl => { name => 'nlst' }, nossl => { name => 'ls'} }, + ls => { ssl => { name => 'list' }, nossl => { name => 'dir'} }, ); sub new { @@ -144,8 +143,12 @@ sub countFiles { next; } - foreach my $file (@files) { - my $name = $dir . '/' . basename($file); + foreach my $line (@files) { + next if ($line !~ /(\S+)\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+\S+\s+(.*)/); + my ($rights, $filename) = ($1, $2); + my $bname = basename($filename); + next if ($bname eq '.' || $bname eq '..'); + my $name = $dir . '/' . $bname; if (defined($self->{option_results}->{filter_file}) && $self->{option_results}->{filter_file} ne '' && $name !~ /$self->{option_results}->{filter_file}/) { @@ -153,9 +156,7 @@ sub countFiles { next; } - if (!(my $time_result = apps::protocols::ftp::lib::ftp::execute($self, - command => $map_commands{mdtm}->{$self->{ssl_or_not}}->{name}, - command_args => [$name]))) { + if ($rights =~ /^d/i) { if (defined($self->{option_results}->{max_depth}) && $level + 1 <= $self->{option_results}->{max_depth}) { push @$list, { name => $name, level => $level + 1}; } @@ -163,7 +164,7 @@ sub countFiles { $self->{output}->output_add(long_msg => sprintf("Match '%s'", $name)); $count++; } - } + } } } return $count; @@ -195,7 +196,7 @@ Need Perl 'Net::FTPSSL' module =item B<--ftp-options> Add custom ftp options. -Example: --ftp-options='Debug=1" --ftp-options='useSSL=1" +Example: --ftp-options='Debug=1" --ftp-options='useSSL=1' =item B<--username> diff --git a/apps/protocols/ftp/mode/login.pm b/apps/protocols/ftp/mode/login.pm index 66bf4e242..48635f680 100644 --- a/apps/protocols/ftp/mode/login.pm +++ b/apps/protocols/ftp/mode/login.pm @@ -131,7 +131,7 @@ Need Perl 'Net::FTPSSL' module =item B<--ftp-options> Add custom ftp options. -Example: --ftp-options='Debug=1" --ftp-options='useSSL=1" +Example: --ftp-options='Debug=1" --ftp-options='useSSL=1' =item B<--username>