http://www.perlmonks.org?node_id=182444

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:

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!