4 Classes that facilitate file transfer (between Web Server and CIS).
6 They may extend BaseFileTransferer class.
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 = ftplib.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)
34 local_fn = os.path.join(self.local_path, crt_fn)
35 remote_fn = os.path.join(self.remote_path, crt_fn)
37 file_local = open(local_fn, 'wb')
39 raise api_exceptions.FileTransferException( \
40 "Could not open local file '%s' for writing: %s" \
41 % (local_fn, repr(e)))
44 self.ftp.cwd(self.remote_path)
45 self.ftp.retrbinary('RETR %s' % crt_fn, file_local.write)
47 except ftplib.error_perm as e:
48 raise api_exceptions.FileTransferException( \
49 "Could not get file '%s' from Web Server: %s" \
50 % (remote_fn, repr(e)))
54 local_fn = os.path.join(self.local_path, crt_fn)
55 remote_fn = os.path.join(self.local_path, crt_fn)
58 file_local = open(local_fn, 'rb')
60 raise api_exceptions.FileTransferException( \
61 "Could not open local file '%s' for reading: %s" \
62 % (local_fn, repr(e)))
65 self.ftp.cwd(self.remote_path)
66 self.ftp.storbinary('STOR %s' % crt_fn, file_local)
68 except ftplib.error_perm as e:
69 raise api_exceptions.FileTransferException( \
70 "Could not get file '%s' from Web Server: %s" \
71 % (remote_fn, repr(e)))
74 if self.ftp is not None: