From ae7c2fb87bf2a6c5df6dfdef02a083d9f4624696 Mon Sep 17 00:00:00 2001 From: Tom Keffer Date: Fri, 27 Oct 2017 05:48:25 -0700 Subject: [PATCH] Introduced FTP option `secure_data`. Fixes issue #284. --- bin/weeutil/ftpupload.py | 13 ++++++++++--- bin/weewx/reportengine.py | 3 ++- docs/changes.txt | 5 ++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/bin/weeutil/ftpupload.py b/bin/weeutil/ftpupload.py index 683701b9..2a00a9b5 100644 --- a/bin/weeutil/ftpupload.py +++ b/bin/weeutil/ftpupload.py @@ -27,7 +27,8 @@ class FtpUpload(object): passive = True, max_tries = 3, secure = False, - debug = 0): + debug = 0, + secure_data = True): """Initialize an instance of FtpUpload. After initializing, call method run() to perform the upload. @@ -50,6 +51,11 @@ class FtpUpload(object): secure: Set to True to attempt an FTP over TLS (FTPS) session. debug: Set to 1 for extra debug information, 0 otherwise. + + secure_data: If a secure session is requested (option secure=True), + should we attempt a secure data connection as well? This option is useful + due to a bug in the Python FTP client library. See Issue #284. + [Optional. Default is True] """ self.server = server self.user = user @@ -62,6 +68,7 @@ class FtpUpload(object): self.max_tries = max_tries self.secure = secure self.debug = debug + self.secure_data = secure_data def run(self): """Perform the actual upload. @@ -99,9 +106,9 @@ class FtpUpload(object): ftp_server.login(self.user, self.password) ftp_server.set_pasv(self.passive) - if self.secure: + if self.secure and self.secure_data: ftp_server.prot_p() - syslog.syslog(syslog.LOG_DEBUG, "ftpupload: Secure connection to %s" % self.server) + syslog.syslog(syslog.LOG_DEBUG, "ftpupload: Secure data connection to %s" % self.server) else: syslog.syslog(syslog.LOG_DEBUG, "ftpupload: Connected to %s" % self.server) break diff --git a/bin/weewx/reportengine.py b/bin/weewx/reportengine.py index 39a8ab8d..c9018e3d 100644 --- a/bin/weewx/reportengine.py +++ b/bin/weewx/reportengine.py @@ -314,7 +314,8 @@ class FtpGenerator(ReportGenerator): passive=to_bool(self.skin_dict.get('passive', True)), max_tries=int(self.skin_dict.get('max_tries', 3)), secure=to_bool(self.skin_dict.get('secure_ftp', False)), - debug=int(self.skin_dict.get('debug', 0))) + debug=int(self.skin_dict.get('debug', 0)), + secure_data=to_bool(self.skin_dict.get('secure_data', True))) except Exception: syslog.syslog(syslog.LOG_DEBUG, "ftpgenerator: FTP upload not requested. Skipped.") diff --git a/docs/changes.txt b/docs/changes.txt index 5866b9a4..0fd29a01 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -1,7 +1,7 @@ weewx change history -------------------- -3.8.0a1 10/xx/2017 +3.8.0a3 10/xx/2017 The `stats.py` example now works with heating and cooling degree days. Fixes issue #224. @@ -29,6 +29,9 @@ and allows additional headers to be added to the HTTP request object. MySQL error 2006 ("MySQL server has gone away") now gets mapped to `weedb.CannotConnectError`. PR #246 +Whether to use a FTP secure data connection is now set separately +from whether to authenticate using TLS. Fixes issue #284. + Corrected formatting used to report indoor temp and humidity to the Weather Underground.