Net::FTP: cwd(' ')

J

Josef Moellers

Hi,

I have this problem:

I'd like to access a directory named ' ' (a single blank) on an ftp server.
I can connect all right, but the $ftp->cwd(' '), while succeeding, only
moves me to /, rather than into the directory.
I've also tried '" "' and '\ ' to no avail.

#!/usr/bin/perl
use Net::FTP;

my $host = 'X.Y.Z';
my $username = 'anonymous';
my $password = 'anonymous';

my $dir = ' ';

$ftp=Net::FTP->new($host,Timeout=>240) or die "Cannot connect";
print "Connected\n";

$ftp->login($username, $password) or die "Cannot login";
print "Logged in\n";

$ftp->cwd($dir) or die "Cannot chdir to blank";
print "Now in ", $ftp->pwd, "\n";

my @files = $ftp->ls or die "Cannot get file list";
foreach (@files) {
print ">$_<\n";
}
$ftp->quit;
 
D

Damian James

I'd like to access a directory named ' ' (a single blank) on an ftp server.
I can connect all right, but the $ftp->cwd(' '), while succeeding, only
moves me to /, rather than into the directory.
I've also tried '" "' and '\ ' to no avail.

Hmmm

puli% mkdir foo
puli% mkdir foo/\
puli% touch foo/\ /bar
puli% perl -le 'system "ls $_" for glob "test/*"'

puli% perl -le 's/[ ]/\\$&/, system "ls $_" for glob "foo/*"'
bar


Remember that to put a literal backslash in a string, even in single
quotes, you need to escape it. So that should be '\\ '.

--damian
 
J

Josef Moellers

Damian said:
I'd like to access a directory named ' ' (a single blank) on an ftp server.
I can connect all right, but the $ftp->cwd(' '), while succeeding, only
moves me to /, rather than into the directory.
I've also tried '" "' and '\ ' to no avail.


Hmmm

puli% mkdir foo
puli% mkdir foo/\
puli% touch foo/\ /bar
puli% perl -le 'system "ls $_" for glob "test/*"'

puli% perl -le 's/[ ]/\\$&/, system "ls $_" for glob "foo/*"'
bar


Remember that to put a literal backslash in a string, even in single
quotes, you need to escape it. So that should be '\\ '.

Thanks for the hint, but it seems to be a special case of Net::FTP:

$dir = "/" unless defined($dir) && $dir =~ /\S/;

If I remove the check for a non-blank character, I get

"Invalid number of arguments." as the result of $ftp->message.

None of '\ ', '\\ ', '" "' work.

Sigh,

Josef
 
S

Sisyphus

Hi,

I have this problem:

I'd like to access a directory named ' ' (a single blank) on an ftp server.
--------------------

Heh ... I guess it *is* a problem for you .... but the person with the
*real* problem is the braindead halfsmart that gave it that name :)

G'luck.

Cheers,
Rob
 
D

Damian James

...
Thanks for the hint, but it seems to be a special case of Net::FTP:

$dir =3D "/" unless defined($dir) && $dir =3D~ /\S/;

Well, your string would pass that test if it still contains a backslash.

If you're going over the code in Net::FTP, you'll also want to look at
Net::Cmd, but you probably knew that.
If I remove the check for a non-blank character, I get
"Invalid number of arguments." as the result of $ftp->message.
None of '\ ', '\\ ', '" "' work.

What happens when you try to cwd into ' ' with an interactive ftp client?

--damian
 
J

Josef Moellers

Damian said:
What happens when you try to cwd into ' ' with an interactive ftp client?

Hmm, good question.
I thought that I had been able to do a 'cd " "' and that would work.
When I try this now, I get exactly the same error messages perl gives me.

I did try this on various systems, though, two of them were different
releases of SuSE Linux (9.0 and 9.1), and I think I also tried this on a
proprietary system. Maybe it worked on the latter.

I think I'll dig through the Net::Ftp, Net::Cmd and related stuff some more.
It has now become more of an academic question: I have talked to the
admin of the remote system and she changed the directory name to
something more accessable.

Josef
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,739
Latest member
Clint8040

Latest Threads

Top