Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Ways to limit bandwidth of downloads?

by jhourcle (Prior)
on Apr 18, 2006 at 15:21 UTC ( [id://544097]=note: print w/replies, xml ) Need Help??


in reply to Ways to limit bandwidth of downloads?

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.

  • Comment on Re: Ways to limit bandwidth of downloads?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://544097]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2024-04-18 06:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found