Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Net::FTP->dir("abc def"); embedded spaces in filename fails.

by justanyone (Acolyte)
on Jul 17, 2002 at 14:55 UTC ( [id://182444]=perlquestion: print w/replies, xml ) Need Help??

justanyone has asked for the wisdom of the Perl Monks concerning the following question:

Hello!

I'm trying to retrieve files and directories off an FTP server where the filenames and directory names both have embedded spaces. Microsoft allows and encourages spaces in filenames, so this is probably common.

I'm trying to use Net::FTP to get a directory listing of a dir with embedded spaces in the name, and also do an FTP get on the files in that directory. Alas, this seems impossible.

The FTP server is "Microsoft FTP Service (Version 5.0)", the client is on Solaris, but I don't think it matters. I'm using Net::FTP 2.64.

I've tried and failed with:

  • Net::FTP->dir("\"abc def\"");
  • Net::FTP->dir("\'abc def\'");
  • Net::FTP->dir("abc\ def");
  • Net::FTP->dir("abc%20def");

Replies are listed 'Best First'.
Re: Net::FTP->dir(
by amphiplex (Monk) on Jul 17, 2002 at 15:09 UTC
    Try using the ls() method, it worked for me connecting to a wuftpd on linux.

    Looks as if dir() generates a LIST command, while ls() generates an NLST command. The former calls /bin/ls.

    debug output:
    Net::FTP=GLOB(0x8293290)<<< 220 central.node.at FTP server (Version 6. +5/OpenBSD, linux port 0.3.2) ready. Net::FTP=GLOB(0x8293290)>>> user kurt Net::FTP=GLOB(0x8293290)<<< 331 Password required for kurt. Net::FTP=GLOB(0x8293290)>>> PASS .... Net::FTP=GLOB(0x8293290)<<< 230- Have a lot of fun... Net::FTP=GLOB(0x8293290)<<< 230 User kurt logged in. Net::FTP=GLOB(0x8293290)>>> CWD /home/kurt/ Net::FTP=GLOB(0x8293290)<<< 250 CWD command successful. Net::FTP=GLOB(0x8293290)>>> PASV Net::FTP=GLOB(0x8293290)<<< 227 Entering Passive Mode (127,0,0,1,183,2 +25) Net::FTP=GLOB(0x8293290)>>> LIST test file Net::FTP=GLOB(0x8293290)<<< 150 Opening BINARY mode data connection fo +r '/bin/ls'. Net::FTP=GLOB(0x8293290)<<< 226 Transfer complete. DIR: [in.ftpd: file: No such file or directoryin.ftpd: test: No such f +ile or directory] Net::FTP=GLOB(0x8293290)>>> PASV Net::FTP=GLOB(0x8293290)<<< 227 Entering Passive Mode (127,0,0,1,183,2 +27) Net::FTP=GLOB(0x8293290)>>> NLST test file Net::FTP=GLOB(0x8293290)<<< 150 Opening BINARY mode data connection fo +r 'file list'. Net::FTP=GLOB(0x8293290)<<< 226 Transfer complete. LS: [test file]
    generated by
    $ftp = Net::FTP->new($destination, Debug=>2) || die "Couldn't connect: + $!\n"; $ftp->login($username,$password) || die "Couldn't log in: $!\n"; $ftp->cwd($path) || die "couldn't cwd! $!\n"; print STDERR "DIR: [",$ftp->dir($filename),"]\n"; print STDERR "LS: [",$ftp->ls($filename),"]\n";
    --- amphiplex
Re: Net::FTP->dir(
by fedelman (Novice) on Jan 22, 2004 at 18:39 UTC
    Hi! It's simple.

    You need run the next commands:
    ...
    ...
    ...
    $filename =~ s/\s/\\ /g;
    $ftp->dir($filename);

    This is the correct way to escape the whitespaces.
    That's all!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://182444]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 05:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found