def test_download(self): ftpd = CurlDownload(self.PROTOCOL, "test.rebex.net", "/") ftpd.set_credentials("demo:password") (file_list, dir_list) = ftpd.list() ftpd.match([r'^readme.txt$'], file_list, dir_list) ftpd.download(self.utils.data_dir) ftpd.close() self.assertTrue(len(ftpd.files_to_download) == 1)
def test_ftps_list_no_ssl(self): # This server is misconfigured hence we disable all SSL verification SERVER = "demo.wftpserver.com" DIRECTORY = "/download/" CREDENTIALS = "demo-user:demo-user" ftpd = CurlDownload(self.PROTOCOL, SERVER, DIRECTORY) ftpd.set_options(dict(ssl_verifyhost="False", ssl_verifypeer="False")) ftpd.set_credentials(CREDENTIALS) (file_list, dir_list) = ftpd.list() ftpd.close() self.assertTrue(len(file_list) > 1)
def test_download_no_ssl(self): # This server is misconfigured hence we disable all SSL verification SERVER = "demo.wftpserver.com" DIRECTORY = "/download/" CREDENTIALS = "demo-user:demo-user" ftpd = CurlDownload(self.PROTOCOL, SERVER, DIRECTORY) ftpd.set_options(dict(ssl_verifyhost="False", ssl_verifypeer="False")) ftpd.set_credentials(CREDENTIALS) (file_list, dir_list) = ftpd.list() ftpd.match([r'^manual_en.pdf$'], file_list, dir_list) ftpd.download(self.utils.data_dir) ftpd.close() self.assertTrue(len(ftpd.files_to_download) == 1)
def test_download_ftp_method(self): """ Test setting ftp_method (it probably doesn't change anything here but we test that there is no obvious mistake in the code). """ ftpd = CurlDownload("ftp", "test.rebex.net", "/") ftpd.set_options(dict(ftp_method="nocwd")) ftpd.set_credentials("demo:password") (file_list, dir_list) = ftpd.list() ftpd.match(["^readme.txt$"], file_list, dir_list) ftpd.download(self.utils.data_dir) ftpd.close() self.assertTrue(len(ftpd.files_to_download) == 1)
def test_download_ssl_certficate(self): # This server is misconfigured but we use its certificate # The hostname is wrong so we disable host verification SERVER = "demo.wftpserver.com" DIRECTORY = "/download/" CREDENTIALS = "demo-user:demo-user" ftpd = CurlDownload(self.PROTOCOL, SERVER, DIRECTORY) curdir = os.path.dirname(os.path.realpath(__file__)) cert_file = os.path.join(curdir, "caert.demo.wftpserver.com.pem") ftpd.set_options( dict(ssl_verifyhost="False", ssl_server_cert=cert_file)) ftpd.set_credentials(CREDENTIALS) (file_list, dir_list) = ftpd.list() ftpd.match([r'^manual_en.pdf$'], file_list, dir_list) ftpd.download(self.utils.data_dir) ftpd.close() self.assertTrue(len(ftpd.files_to_download) == 1)
def test_ftps_list(self): ftpd = CurlDownload(self.PROTOCOL, "test.rebex.net", "/") ftpd.set_credentials("demo:password") (file_list, dir_list) = ftpd.list() ftpd.close() self.assertTrue(len(file_list) == 1)
def get_handler(self, protocol_name, server, remote_dir, remote_files=[], credentials=None, http_parse=None, http_method=None, param=None, proxy=None, proxy_auth='', save_as=None, timeout_download=None, offline_dir=None, options={}): protocol = downmessage_pb2.DownloadFile.Protocol.Value( protocol_name.upper()) downloader = None if protocol in [0, 1]: # FTP, SFTP downloader = CurlDownload(protocol_name, server, remote_dir) if protocol in [ 2, 3 ]: # HTTP, HTTPS (could be factored with previous case) downloader = CurlDownload(protocol_name, server, remote_dir, http_parse) if protocol == 4: # DirectFTP downloader = DirectFTPDownload("ftp", server, '/') if protocol == 5: # DirectHTTP downloader = DirectHTTPDownload("http", server, '/') if protocol == 6: # DirectHTTPS downloader = DirectHTTPDownload("https", server, '/') if protocol == 10: # DirectFTPS downloader = DirectFTPDownload('ftps', server, '/') if protocol == 7: # Local downloader = LocalDownload(remote_dir) if protocol == 8: # RSYNC downloader = RSYNCDownload(server, remote_dir) if protocol == 9: # iRods downloader = IRODSDownload(server, remote_dir) if downloader is None: return None for remote_file in remote_files: if remote_file['save_as']: save_as = remote_file['save_as'] # For direct protocols, we only keep base name if protocol in DIRECT_PROTOCOLS: tmp_remote = [] for remote_file in remote_files: tmp_remote.append(remote_file['name']) remote_files = tmp_remote if http_method is not None: downloader.set_method(http_method) if offline_dir: downloader.set_offline_dir(offline_dir) if proxy is not None and proxy: downloader.set_proxy(proxy, proxy_auth) if timeout_download is not None and timeout_download: downloader.set_timeout(timeout_download) if credentials: downloader.set_credentials(credentials) if save_as: downloader.set_save_as(save_as) if param: downloader.set_param(param) downloader.set_server(server) # Set the name of the BioMAJ protocol to which we respond. downloader.set_protocol(protocol_name) if options is not None: self.logger.debug("Received options: " + str(options)) downloader.set_options(options) downloader.logger = self.logger downloader.set_files_to_download(remote_files) return downloader