Skip to content

Commit 191ab7b

Browse files
authored
Merge pull request #50 from usegalaxy-eu/ftps
Adding TLS to the ftp connection
2 parents 5f820c0 + 8356115 commit 191ab7b

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

ena_upload/ena_upload.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@
2222
from ena_upload._version import __version__
2323

2424

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+
2535
def create_dataframe(schema_tables, action):
2636
'''create pandas dataframe from the tables in schema_tables
2737
and return schema_dataframe
@@ -343,22 +353,28 @@ def submit_data(file_paths, password, webin_id):
343353
:param file_paths: a dictionary of filename string and file_path string
344354
:param args: the command-line arguments parsed by ArgumentParser
345355
"""
356+
ftp_host = "webin2.ebi.ac.uk"
346357

358+
print("\nConnecting to ftp.webin.ebi.ac.uk....")
347359
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+
350367
except IOError:
351-
print(ftp.lastErrorText())
368+
print(ftps.lastErrorText())
352369
print("ERROR: could not connect to the ftp server.\
353370
Please check your login details.")
354-
355371
for filename, path in file_paths.items():
356372
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'))
359375
print(msg)
360376

361-
print(ftp.quit())
377+
print(ftps.quit())
362378

363379
def columns_to_update(df):
364380
'''

0 commit comments

Comments
 (0)