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 self.ftp.cwd(self.remote_path)
35 except ftplib.error_perm as e:
36 raise api_exceptions.FileTransferException( \
37 "Could not change remote directory '%s': %s" \
38 % (self.remote_path, repr(e)))
42 local_fn = os.path.join(self.local_path, crt_fn)
43 remote_fn = os.path.join(self.remote_path, crt_fn)
45 file_local = open(local_fn, 'wb')
47 raise api_exceptions.FileTransferException( \
48 "Could not open local file '%s' for writing: %s" \
49 % (local_fn, repr(e)))
52 self.ftp.retrbinary('RETR %s' % crt_fn, file_local.write)
54 except ftplib.error_perm as e:
55 raise api_exceptions.FileTransferException( \
56 "Could not get file '%s' from Web Server: %s" \
57 % (remote_fn, repr(e)))
61 self.ftp.cwd(self.remote_path)
62 except ftplib.error_perm as e:
63 raise api_exceptions.FileTransferException( \
64 "Could not change remote directory '%s': %s" \
65 % (self.remote_path, repr(e)))
68 local_fn = os.path.join(self.local_path, crt_fn)
71 file_local = open(local_fn, 'rb')
73 raise api_exceptions.FileTransferException( \
74 "Could not open local file '%s' for reading: %s" \
75 % (local_fn, repr(e)))
78 print('remote_path=' + self.remote_path \
79 + '; crt_fn=' + crt_fn)
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: