4 Classes that facilitate file transfer (between Web Server and CIS).
6 They may extend BaseFileTransferer class.
20 class FTPFileTransferer(base.BaseFileTransferer):
22 FTPS implementation for file transfering between Web Server and CIS.
27 def __init__(self, local_path='', remote_path=''):
28 base.BaseFileTransferer.__init__(self, local_path, remote_path)
30 self.ftp = ftplib.FTP_TLS(ftp_config.FTP_HOST, ftp_config.FTP_USER,
31 ftp_config.FTP_PASSWD, ftp_config.FTP_ACCT)
32 self.ftp.set_pasv(True)
36 self.ftp.cwd(self.remote_path)
37 except ftplib.error_perm as e:
38 raise api_exceptions.FileTransferException( \
39 "Could not change remote directory '%s': %s" \
40 % (self.remote_path, repr(e)))
44 local_fn = os.path.join(self.local_path, crt_fn)
45 remote_fn = os.path.join(self.remote_path, crt_fn)
47 file_local = open(local_fn, 'wb')
49 raise api_exceptions.FileTransferException( \
50 "Could not open local file '%s' for writing: %s" \
51 % (local_fn, repr(e)))
54 self.ftp.retrbinary('RETR %s' % crt_fn, file_local.write)
56 except ftplib.error_perm as e:
57 raise api_exceptions.FileTransferException( \
58 "Could not get file '%s' from Web Server: %s" \
59 % (remote_fn, repr(e)))
63 self.ftp.cwd(self.remote_path)
64 except ftplib.error_perm as e:
65 raise api_exceptions.FileTransferException( \
66 "Could not change remote directory '%s': %s" \
67 % (self.remote_path, repr(e)))
70 local_fn = os.path.join(self.local_path, crt_fn)
73 file_local = open(local_fn, 'rb')
75 raise api_exceptions.FileTransferException( \
76 "Could not open local file '%s' for reading: %s" \
77 % (local_fn, repr(e)))
80 self.ftp.storbinary('STOR %s' % crt_fn, file_local)
82 except ftplib.error_perm as e:
83 raise api_exceptions.FileTransferException( \
84 "Could not put file '%s' to Web Server: %s" \
85 % (local_fn, repr(e)))
88 if self.ftp is not None: