Home > Archive > PERL Miscellaneous > June 2005 > Net::FTP: cwd(' ')
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Net::FTP: cwd(' ')
|
|
| Josef Moellers 2005-06-08, 8:58 am |
| Hi,
I have this problem:
I'd like to access a directory named ' ' (a single blank) on an ftp serve=
r.
I can connect all right, but the $ftp->cwd(' '), while succeeding, only=20
moves me to /, rather than into the directory.
I've also tried '" "' and '\ ' to no avail.
#!/usr/bin/perl
use Net::FTP;
my $host =3D 'X.Y.Z';
my $username =3D 'anonymous';
my $password =3D 'anonymous';
my $dir =3D ' ';
$ftp=3DNet::FTP->new($host,Timeout=3D>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 =3D $ftp->ls or die "Cannot get file list";
foreach (@files) {
print ">$_<\n";
}
$ftp->quit;
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
| |
| Damian James 2005-06-08, 8:58 am |
| On Wed, 08 Jun 2005 10:36:23 +0200, Josef Moellers 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 '\\ '.
--damian
| |
| Josef Moellers 2005-06-08, 8:58 am |
| Damian James wrote:
> On Wed, 08 Jun 2005 10:36:23 +0200, Josef Moellers said:
>=20
ver.[color=darkred]
[color=darkred]
>=20
>=20
> Hmmm
>=20
> puli% mkdir foo
> puli% mkdir foo/\=20
> puli% touch foo/\ /bar
> puli% perl -le 'system "ls $_" for glob "test/*"'
>=20
> puli% perl -le 's/[ ]/\\$&/, system "ls $_" for glob "foo/*"'
> bar
>=20
>=20
> 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 =3D "/" unless defined($dir) && $dir =3D~ /\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
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
| |
| Sisyphus 2005-06-08, 3:59 pm |
|
"Josef Moellers" <josef.moellers@fujitsu-siemens.com> wrote in message
news:d86agm$7s6$1@nntp.fujitsu-siemens.com...
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
| |
| Damian James 2005-06-08, 8:57 pm |
| On Wed, 08 Jun 2005 12:57:42 +0200, Josef Moellers said:
> ...
> 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
| |
| Josef Moellers 2005-06-09, 8:57 am |
| Damian James wrote:
>=20
>=20
> What happens when you try to cwd into ' ' with an interactive ftp clien=
t?
Hmm, good question.
I thought that I had been able to do a 'cd " "' and that would work.=20
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=20
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 mo=
re.
It has now become more of an academic question: I have talked to the=20
admin of the remote system and she changed the directory name to=20
something more accessable.
Josef
--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize
-- T. Pratchett
|
|
|
|
|