[snip] > > > > Interesting use of LWP, I wouldn't have thought of doing it that way, > > which certainly doesn't make it wrong! > > Thanks, I think. :) I'm sure my code is full of 'interesting' uses! >
As long as it works and you (and your boss) are happy with it... > > I probably should have stated > > specifically that I was being adamant *about using a module* for FTP > > transactions rather than doing it some other kludge of a way. > > Absolutely. > > > Generally > > I would think the simplest module is Net::FTP, but since LWP provides > > functionality as long as it fits what you need to do then by > > all means... > > > > Having said that, personally I don't think it fits very well what you > > are attempting to do, since I have a hunch LWP was intended to make > > handling FTP urls found in web pages simple, rather than providing a > > true interface to FTP, which is Net::FTP's sole and intended purpose. > > Specifically in your case fetching the file size requires > > either parsing > > of a directory listing or HEAD request, and you had to write your own > > functions to do it, which means they have to be > > maintained/tested, etc. > > while Net::FTP provides the 'size' method for you. > > In truth, I used LWP because I was already using it in another part of the > program, and because I thought the 'head' and 'getstore' functions would do > what I needed (so it was out of laziness more than anything). These are very good reasons. The situation should be allowed to dictate which tools are used, and I (we) know very little about your situation. Should you use a hammer to pound in a nail? Not if you are on the roof of a 3 story house, the nail is really big, the only hammer you have access to is for finishing nails and is in the basement *and* there is a brick laying beside you.... On the other hand if there is a hammer hanging from your hip and you are currently holding a screwdriver, should you use the hammer over the screwdriver, probably.... Now that I > look at it, I agree Net::FTP looks like a more appropriate module than LWP. > It appears to be purely OO, though, and I prefer a more procedural interface > - do you know if Net::FTP supports that? Not sure... doubt it though, because of how Perl handles OOP you could just hack it up in a procedural way, though I wouldn't necessarily suggest it. > > > There are other reasons for preferring Net::FTP over LWP for this > > specific type of task, more specific return codes, already provided > > routines such as 'size', continuous connection (aka LWP implements FTP > > using HTTP like request, aka a single action at a time) while with > > Net::FTP you could handle several transactions over a single > > connection, for instance checking the size of the file, downloading it > > if it is over a certain size, and then moving the remote file to a new > > location. Depending on the size of your files or the number of actions > > needed, the time to establish connections could be the longest part of > > the process. > > All very good points. They never occurred to me, so it's good to hear the > reasoning behind why one module might be better than another (given a certain > set of circumstances). Those last 6 words are probably the most important to a programmer. To me, when you can ask those questions and either answer them or know how to find the answers then you have begun programming, no matter how many lines of code you may have previously written... I find it easier to learn when I understand WHY I > should use A instead of B, instead of just reading something that says to use > A but fails to give an example or the logic behind it. > Yep many of us are probably the same, I am... > That said, would Net::FTP still be the preferred module if the file you're > downloading is NOT on an ftp server? For example, I am downloading flat text > data files. Some of them are on an ftp site (cue Net::FTP, stage right), but > some of them aren't. Specifically, they have a http address and, when the > link to them is clicked, they are displayed as text instead of downloaded. > So would LWP be appropriate for those files, or would Net::FTP still be the > way to go? > Net::FTP would not be the way to go, likely *can't* be the way to go at least for the HTTP files. This is where an underlying understanding of what FTP and HTTP really are, comes into play and how they function in the client/server model. If the remote host provides a file via HTTP it may not (likely won't) provide the same file via FTP, and vice versa. This makes LWP a good tool since it provides the same interface to both protocols, essentially by reducing the protocols to their common factors. Otherwise you would need to code in a check that establishes whether a link is FTP or HTTP and call different code for each different type, which is why the LWP interface is so nice (and essentially what it is doing) for parsing links that are contained in webpages and just getting whatever is at the other end. Now we are getting into the SDLC, and rhetorical discussion... Is it more important to you to have a unified interface, only need to support a single module, etc. Or is it better to have maximum flexibility and power at the cost of having to maintain multiple interfaces and modules? Only your situation (including what you consider production code, how long it takes to release/migrate, testing requirements, physical resources, etc.), needs, and future expectations can really tell you... But to decide it helps to know all of the possiblities. HTH, http://danconia.org -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>