libdlm.file_downloader

Downloads a standard file from http or ftp locations.

Original Author: Joshua Banton Original GitHub: https://github.com/bantonj/fileDownloader

class libdlm.file_downloader.FileDownloader(url, local_file_dir=None, local_file_name=None, username=None, password=None, timeout=120.0, retries=5, logger=None, max_segments=10)

This class is used for downloading files from the internet via http or ftp. It supports basic http authentication and ftp accounts, and supports resuming downloads. It does not support https or sftp at this time.

The main advantage of this class is it’s ease of use, and pure pythoness.

If a non-standard port is needed just include it in the url (http://example.com:7632).

Basic usage: >>> downloader = FileDownloader(‘http://example.com/file.zip‘) >>> downloader.download()

Use full path to download >>> downloader = FileDownloader(‘http://example.com/file.zip‘,

“C:/Users/username/Downloads/newfilename.zip”)
>>> downloader.download()

Basic Authentication protected download >>> downloader = FileDownloader(‘http://example.com/file.zip‘,

“C:/Users/username/Downloads/newfilename.zip”, (‘username’,’password’))
>>> downloader.download()

Resume >>> downloader = FileDownloader(‘http://example.com/file.zip‘) >>> downloader.resume()

check_exists()

Checks to see if the file in the url in self.url exists

download(callback=None)

starts the file download

get_local_file_size()

gets filesize of local file

get_url_file_name(url)

returns filename from url

get_url_file_size()

gets filesize of remote file from ftp or http server

resume(callback=None)

attempts to resume file download