Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

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

( #182444=categorized question: print w/ replies, xml ) Need Help??
Contributed by justanyone on Jul 17, 2002 at 14:55 UTC
Q&A  > HTTP and FTP clients


Description:

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");

Answer: Net::FTP->dir(
contributed by amphiplex

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
Answer: Net::FTP->dir(
contributed by fedelman

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!

Please (register and) log in if you wish to add an answer



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (8)
    As of 2014-08-02 09:09 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      Who would be the most fun to work for?















      Results (55 votes), past polls