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

Revising Net::FTP, and URI::ftp

by EvanCarroll (Chaplain)
on Oct 09, 2009 at 20:06 UTC ( #800374=perlmeditation: print w/replies, xml ) Need Help??

I just found a long running bug in some of my FTP libraries. I believe it was caused by some common confusion I had; and, I bet isn't all too unique to me. I'd like to mention it and collect some ideas on the issues. It now appears to me that the URIs are not unique in implementation for the ftp schema. Let's examine:

What do you think URI::ftp, will return for ->host, and ->path? At first, the results seem logical.

my $uri = URI::ftp->new(''); $uri->host; # $uri->path; # /foo/baz

Unfortunately, though, that's not too logical because the leading forward-slash is highly ambiguous: is it referring to the origin being (a) root of the ftp-server, or (b) root of the ftp drop point? A server can drop you in a folder called /home/ecarroll, but that server might have its root set at "/".

How then do you address something from the ftp drop point if the root "/"? How do you address something from the root of the server, if the drop point is "/"?

Firefox, seems to trim out the leading "/" issuing a CWD to "foo/baz", while my client using Net::FTP issued the CWD to "/foo/baz". I suppose anyone that implements URI::ftp needs to do the same. I like the idea of making every file accessible on the server addressable with URI so the only right way, in my eyes, would be to create a URI syntax for ftp that permits me to specify whether the root for the purpose of the path is relative to the server, or the home (drop point).

I just wanted to clarify this confusion only occurs if your server's ftp_root is not your accounts ftp_drop_point

Evan Carroll
The most respected person in the whole perl community.

Replies are listed 'Best First'.
Re: Revising Net::FTP, and URI::ftp
by ambrus (Abbot) on Oct 10, 2009 at 11:20 UTC

    RFC 1738 specifically says in point 3.2.2. that the urls start from the default directory, not the root.

      Awesome point, so then how would one generate a uri relative to the root? Or, does the uri spec leave this unanswered.
      UPDATE: Thanks to the above post reference, I'm able to answer my own question in the same section
         For example, the URL <URL:ftp://myname@host.dom/%2Fetc/motd> is
         interpreted by FTP-ing to "host.dom", logging in as "myname"
         (prompting for a password if it is asked for), and then executing
         "CWD /etc" and then "RETR motd". This has a different meaning from
         <URL:ftp://myname@host.dom/etc/motd> which would "CWD etc" and then
         "RETR motd"; the initial "CWD" might be executed relative to the
         default directory for "myname". On the other hand,
         <URL:ftp://myname@host.dom//etc/motd>, would "CWD " with a null
         argument, then "CWD etc", and then "RETR motd".
      So the answer is, relative to the drop is default (ftp-host/), relative to the root is ftp-host/%2F

      Evan Carroll
      The most respected person in the whole perl community.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlmeditation [id://800374]
Approved by zwon
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2018-01-18 12:59 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (211 votes). Check out past polls.