Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduced Safer FTP Alternative: Added FTP_TLS #2877

Open
wants to merge 1 commit into
base: python2
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions motioneye/uploadservices.py
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ def __init__(self, camera_id):
self._username = None
self._password = None
self._location = None
self._secure = None

self._conn = None
self._conn_time = 0
Expand Down Expand Up @@ -887,7 +888,8 @@ def dump(self):
'port': self._port,
'username': self._username,
'password': self._password,
'location': self._location
'location': self._location,
'secure': self._secure
}

def load(self, data):
Expand All @@ -901,15 +903,24 @@ def load(self, data):
self._password = data['password']
if data.get('location'):
self._location = data['location']
if data.get('secure') is not None:
self._secure = data['secure']

def _get_conn(self, create=False):
now = time.time()
if self._conn is None or now - self._conn_time > self.CONN_LIFE_TIME or create:
self.debug('creating connection to %s@%s:%s' % (self._username or 'anonymous', self._server, self._port))
self._conn = ftplib.FTP()
self._conn.set_pasv(True)
self._conn.connect(self._server, port=self._port)
self._conn.login(self._username or 'anonymous', self._password)
if self._secure:
self._conn = ftplib.FTP_TLS()
self._conn.set_pasv(True)
self._conn.connect(self._server, port=self._port)
self._conn.login(self._username or 'anonymous', self._password)
self._conn.prot_p()
else:
self._conn = ftplib.FTP()
self._conn.set_pasv(True)
self._conn.connect(self._server, port=self._port)
self._conn.login(self._username or 'anonymous', self._password)
self._conn_time = now

return self._conn
Expand Down