How are the calls to Net::FTP made?

If the system was designed to be maintainable, you'd want to add a level of abstraction -- pass the URL, or the connection details and file path to a function. If it was written for a single use, and then slowly expanded over time w/ copy&pasting as needed, it's possible that are calls to Net::FTP all over the place.

The main code should only need to worry about four things -- did the command work, what is in a directory, where was the file downloaded to, and what were the contents of the file? (normally, you only need the third or fourth one, and not both) I typically have two functions -- get file contents, and download file ... 'get file contents' uses the 'download file' routines or visa-versa (depending on what the modules are that I'm using ... IDL forces me to write everything to files first, then load them back in, whereas in Perl, I'll only write out the files when necessary (if I'm looking at caching, 'get file contents' calls 'download files', if there's no reason to cache, it's probably the other way around)

This way, I can easily add caching, change the underlying code for downloading files, add rate limiting, support for additional transfer protocols, etc, as needed.

Given your situation, I'd probably first write a few tests, and make sure they all pass. I'd then move to encapsulate all of the current calls to Net::FTP, and then make sure that all of the tests still pass. Then I'd go ahead and change the Net::FTP calls to wget or curl, and make sure everything's still working fine.

The next alternative is to write your own FTP object, that has the same interfaces exposed as Net::FTP (it might even inherit from Net::FTP), and replace all of the calls to Net::FTP to 'My::FTP' or whatever you end up calling it.


In reply to Re: Ways to limit bandwidth of downloads? by jhourcle
in thread Ways to limit bandwidth of downloads? by bwelch

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.