4 Classes that facilitate file transfer (between Web Server and CIS).
6 They may extend BaseFileTransferer class.
10 from ftplib import FTP_TLS
18 class FTPFileTransferer(base.BaseFileTransferer):
20 FTPS implementation for file transfering between Web Server and CIS.
25 def __init__(self, local_path='', remote_path=''):
26 base.BaseFileTransferer.__init__(self, local_path, remote_path)
28 self.ftp = FTP_TLS(ftp_config.FTP_HOST, ftp_config.FTP_USER,
29 ftp_config.FTP_PASSWD, ftp_config.FTP_ACCT)
30 self.ftp.set_pasv(True)
33 for crt_file in files:
34 crt_file = os.path.join(self.local_path, crt_file)
36 file_local = open(crt_file, 'wb')
38 raise api_exceptions.FileTransferException( \
39 "Could not open local file '%s' for writing: %s" \
40 % (crt_file, repr(e)))
43 self.ftp.cwd(self.remote_path)
44 self.ftp.retrbinary('RETR %s' % crt_file, file_local.write)
46 except ftplib.error_perm as e:
47 raise api_exceptions.FileTransferException( \
48 "Could not get file '%s' from Web Server: %s" \
49 % (crt_file, repr(e)))
52 for crt_file in files:
53 crt_file = os.path.join(self.local_path, crt_file)
56 file_local = open(crt_file, 'rb')
58 raise api_exceptions.FileTransferException( \
59 "Could not open local file '%s' for reading: %s" \
60 % (crt_file, repr(e)))
63 self.ftp.cwd(self.remote_path)
64 self.ftp.storbinary('STOR %s' % crt_file, file_local)
66 except ftplib.error_perm as e:
67 raise api_exceptions.FileTransferException( \
68 "Could not get file '%s' from Web Server: %s" \
69 % (crt_file, repr(e)))
72 if self.ftp is not None: