|
22 | 22 | from ena_upload._version import __version__
|
23 | 23 |
|
24 | 24 |
|
| 25 | +class MyFTP_TLS(ftplib.FTP_TLS): |
| 26 | + """Explicit FTPS, with shared TLS session""" |
| 27 | + def ntransfercmd(self, cmd, rest=None): |
| 28 | + conn, size = ftplib.FTP.ntransfercmd(self, cmd, rest) |
| 29 | + if self._prot_p: |
| 30 | + conn = self.context.wrap_socket(conn, |
| 31 | + server_hostname=self.host, |
| 32 | + session=self.sock.session) |
| 33 | + return conn, size |
| 34 | + |
25 | 35 | def create_dataframe(schema_tables, action):
|
26 | 36 | '''create pandas dataframe from the tables in schema_tables
|
27 | 37 | and return schema_dataframe
|
@@ -343,22 +353,28 @@ def submit_data(file_paths, password, webin_id):
|
343 | 353 | :param file_paths: a dictionary of filename string and file_path string
|
344 | 354 | :param args: the command-line arguments parsed by ArgumentParser
|
345 | 355 | """
|
| 356 | + ftp_host = "webin2.ebi.ac.uk" |
346 | 357 |
|
| 358 | + print("\nConnecting to ftp.webin.ebi.ac.uk....") |
347 | 359 | try:
|
348 |
| - print("\nConnecting to ftp.webin.ebi.ac.uk....") |
349 |
| - ftp = ftplib.FTP("webin.ebi.ac.uk", webin_id, password) |
| 360 | + ftps = MyFTP_TLS(timeout=10) |
| 361 | + ftps.context.set_ciphers('DEFAULT@SECLEVEL=1') |
| 362 | + ftps.connect(ftp_host, port=21) |
| 363 | + ftps.auth() |
| 364 | + ftps.login(webin_id, password) |
| 365 | + ftps.prot_p() |
| 366 | + |
350 | 367 | except IOError:
|
351 |
| - print(ftp.lastErrorText()) |
| 368 | + print(ftps.lastErrorText()) |
352 | 369 | print("ERROR: could not connect to the ftp server.\
|
353 | 370 | Please check your login details.")
|
354 |
| - |
355 | 371 | for filename, path in file_paths.items():
|
356 | 372 | print(f'uploading {path}')
|
357 |
| - ftp.storbinary(f'STOR {filename}', open(path, 'rb')) |
358 |
| - msg = ftp.storbinary(f'STOR {filename}', open(path, 'rb')) |
| 373 | + ftps.storbinary(f'STOR {filename}', open(path, 'rb')) |
| 374 | + msg = ftps.storbinary(f'STOR {filename}', open(path, 'rb')) |
359 | 375 | print(msg)
|
360 | 376 |
|
361 |
| - print(ftp.quit()) |
| 377 | + print(ftps.quit()) |
362 | 378 |
|
363 | 379 | def columns_to_update(df):
|
364 | 380 | '''
|
|
0 commit comments