Skip Menu |

This queue is for tickets about the Net-SFTP-Foreign CPAN distribution.

Report information
The Basics
Id: 115174
Status: resolved
Priority: 0/
Queue: Net-SFTP-Foreign

People
Owner: Nobody in particular
Requestors: DOUGW [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 1.81
Fixed in: (no value)



Subject: mkpath failed top dir reached on get
Running this: use Cwd; use Net::SFTP::Foreign; my $dir = getcwd; my $ftp = Net::SFTP::Foreign->new('localhost', autodie => 1); $ftp->setcwd($dir); $ftp->get('tmp.txt', 'tmp_test.txt'); $ftp->disconnect(); Getting this on get(): mkpath failed, top dir reached at ./tst line 30.
Seems to fail on 'get' to a file without a path. If I substitute tmp_test.txt with, e.g., '/home/myuser/tmp_test.txt' then it works...but then what would be the point of setcwd() ? Thanks..
This seems to work: sub _mkpath_local { my ($sftp, $path, $perm, $parent) = @_; my @parts = File::Spec->splitdir($path); my @tail; if ($debug and $debug & 32768) { my $target = File::Spec->join(@parts); _debug "_mkpath_local('$target')"; } if ($parent) { pop @parts while @parts and not length $parts[-1]; @parts or goto top_dir_reached; pop @parts; @parts or return 1; } while (1) { my $target = File::Spec->join(@parts); if (!defined $target or -e $target) { if (!defined $target or -d $target) { while (@tail) { $target = defined($target) ? File::Spec->join($target, shift(@tail)) : shift(@tail); $debug and $debug and 32768 and _debug "creating local directory $target"; unless (CORE::mkdir $target, $perm) { unless (do { local $!; -d $target}) { $sftp->_set_error(SFTP_ERR_LOCAL_MKDIR_FAILED, "mkdir '$target' failed", $!); return; } } } return 1; } else { $sftp->_set_error(SFTP_ERR_LOCAL_BAD_OBJECT, "Local file '$target' is not a directory"); return; } } @parts or last; unshift @tail, pop @parts; } top_dir_reached: $sftp->_set_error(SFTP_ERR_LOCAL_MKDIR_FAILED, "mkpath failed, top dir reached"); return; }
Should be fixed now in version 1.83: https://metacpan.org/release/SALVA/Net-SFTP-Foreign-1.83 Could you try it?
On Thu Jun 09 03:38:05 2016, SALVA wrote: Show quoted text
> Could you try it?
The example now works, but now any relative or absolute path that needs a mkdir does not work, e.g.: $ftp->get('tmp.txt', 'foo/tmp_test.txt'); #or $ftp->get('tmp.txt', '/home/runrig/foo/tmp_test.txt');
On Thu Jun 09 11:32:31 2016, DOUGW wrote: Show quoted text
> On Thu Jun 09 03:38:05 2016, SALVA wrote: > $ftp->get('tmp.txt', 'foo/tmp_test.txt'); > #or > $ftp->get('tmp.txt', '/home/runrig/foo/tmp_test.txt');
E.g. the second one gives: mkdir 'home/runrig' failed: No such file or directory at ... (only 'foo' needed to be created). the first one says: mkdir '' failed: No such file or directory at ...
On Thu Jun 09 11:39:08 2016, DOUGW wrote: Show quoted text
> On Thu Jun 09 11:32:31 2016, DOUGW wrote:
> > On Thu Jun 09 03:38:05 2016, SALVA wrote: > > $ftp->get('tmp.txt', 'foo/tmp_test.txt'); > > #or > > $ftp->get('tmp.txt', '/home/runrig/foo/tmp_test.txt');
> > E.g. the second one gives: > mkdir 'home/runrig' failed: No such file or directory at ... > (only 'foo' needed to be created). > > the first one says: > mkdir '' failed: No such file or directory at ...
Both of these examples work with my rewritten _mkpath_local above. (also, multilevel mkdir, e.g. 'foo/bar/tmp_test.txt').
New release 1.85 is available from CPAN: https://metacpan.org/release/SALVA/Net-SFTP-Foreign-1.85 It should be fixed this time!
On Thu Jun 09 12:23:44 2016, SALVA wrote: Show quoted text
> New release 1.85 is available from CPAN: > > https://metacpan.org/release/SALVA/Net-SFTP-Foreign-1.85 > > It should be fixed this time!
Works now! Thanks!
ok, closing. Thank you for reporting the issue!