Subject: | Error creating directory named "0" via _rput |
When using Net::FTP::Recursive to upload a certain directory structure
it always fails when trying to upload a directory named "0" (zero).
I think this happens, because &_rput (line 586) expects to get even 0 or
1 from Net::FTP's &mkdir.
IMHO &mkdir (using _MKD) does not need to return anything. The return
can also be undefined even if directory was created successfully as it
is in case of directory named "0".
Little test.pl and diff attached.
Kind regards - philipp
Subject: | test.pl |
#!/usr/bin/perl
use strict;
use warnings;
use FindBin;
use lib $FindBin::Bin;
use lib $FindBin::Bin .'/libs/';
use Net::FTP::Recursive;
my $host = '127.0.0.1';
my $user = 'john';
my $pass = 'secret';
my $src_dir = 'test_src';
my $dst_dir = '/home/dst_user/dst_test';
unless( -d $src_dir ) {
print STDERR "Source directory does not exist!\n\n";
print STDERR "Create it:\t mkdir -p $src_dir/\{0,1,2}\n\n";
exit(1);
}
&FTP_copyDir(
$host,
$user,
$pass,
$src_dir,
$dst_dir,
1);
sub FTP_connectRecursive {
my $host = shift || die ("Hostname required!\n");
my $debug = shift || 0;
my $FTP = Net::FTP::Recursive->new($host, Debug => $debug, Passive => 1, Timeout => 10) or die ("Cannot connect to $host! $!\n");
return $FTP;
}
sub FTP_copyDir {
my $host = shift || die("Host or IP required!\n");
my $user = shift || die("Username required!\n");
my $pass = shift || die("Password required!\n");
my $src_dir = shift || die("Source directory required!\n");
my $dst_dir = shift || die("Destination directory required!\n");
my $debug = shift || 0;
my $FTP = &FTP_connectRecursive($host, $debug);
if(ref($FTP) ne 'Net::FTP::Recursive') {
print STDERR "FTP_copyDir:\tFTP connection failed!\n";
return 0;
}
if(! $FTP->login($user, $pass) ) {
print STDERR "FTP_copyDir:\tCannot login to server $host with (u:$user, p:xxxx)\n";
return 0;
}
if(! chdir($src_dir) ) {
print STDERR "FTP_copyDir:\tCannot change to directory ($src_dir)! $!\n";
return 0;
}
if(! $FTP->cwd($dst_dir) ) {
print STDERR "FTP_copyDir:\tCannot change to directory ($dst_dir)! $!\n";
return 0;
}
my $ret = $FTP->rput();
if( $ret ne '' ) {
print STDERR "FTP_copyDir:\tCannot copy recursive to ($dst_dir)! $!\n";
print STDERR "FTP_copyDir:\trPUT:$ret\n";
print STDERR "RET::". $ret ."::RET\n";
return 0;
}
$FTP->quit();
return 1;
}
Subject: | 2011-03-10_Net-FTP-Recursive_fix-0-directory_rput.diff |
--- libs/Net/FTP/Recursive.pm.orig 2011-03-09 15:44:23.009437002 +0100
+++ libs/Net/FTP/Recursive.pm 2011-03-09 15:43:27.139437002 +0100
@@ -583,7 +583,13 @@
print STDERR "Making dir: ", $filename, "\n"
if $ftp->debug;
- unless( $ftp->mkdir($filename) ){
+ # unless( $ftp->mkdir($filename) ){
+
+ # FIX:
+ # try to create directory (RFC959 command _MKD)
+ #
+ my $ret = $ftp->mkdir($filename);
+ if(!defined($ret)) {
print STDERR 'Could not make remote directory ',
$filename, "!\n"
if $ftp->debug;