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 cis_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 if os.path.exists(local_fn):
48 raise cis_exceptions.FileAlreadyExistsException( \
49 'file "%s" already exists' % local_fn)
52 file_local = open(local_fn, 'wb')
54 raise cis_exceptions.FileTransferException( \
55 "Could not open local file '%s' for writing: %s" \
56 % (local_fn, repr(e)))
59 self.ftp.retrbinary('RETR %s' % crt_fn, file_local.write)
61 except ftplib.error_perm as e:
62 raise cis_exceptions.FileTransferException( \
63 "Could not get file '%s' from Web Server: %s" \
64 % (remote_fn, repr(e)))
68 self.ftp.cwd(self.remote_path)
69 except ftplib.error_perm as e:
70 raise cis_exceptions.FileTransferException( \
71 "Could not change remote directory '%s': %s" \
72 % (self.remote_path, repr(e)))
75 local_fn = os.path.join(self.local_path, crt_fn)
78 file_local = open(local_fn, 'rb')
80 raise cis_exceptions.FileTransferException( \
81 "Could not open local file '%s' for reading: %s" \
82 % (local_fn, repr(e)))
85 self.ftp.storbinary('STOR %s' % crt_fn, file_local)
87 except ftplib.error_perm as e:
88 raise cis_exceptions.FileTransferException( \
89 "Could not put file '%s' to Web Server: %s" \
90 % (local_fn, repr(e)))
93 if self.ftp is not None: