diff --git a/connect.py b/connect.py index 7f2d730..71d8916 100644 --- a/connect.py +++ b/connect.py @@ -164,12 +164,13 @@ if gw.use_ssh: print("Running SSH server on port {}...".format(gw.ssh_port)) else: print("Running TELNET and FTP servers...") + gw.use_ftp = True requests.get(gw.apiurl + "xqnetdetect/netspeed") time.sleep(0.5) gw.passw = 'root' -gw.ping(contimeout = 8) +gw.ping(contimeout = 12) print("") print("#### Connection to device {} is OK ####".format(gw.device_name)) diff --git a/gateway.py b/gateway.py index 47477cb..b594b4b 100644 --- a/gateway.py +++ b/gateway.py @@ -58,6 +58,7 @@ def get_http_headers(): class Gateway(): def __init_fields(self): self.use_ssh = True + self.use_ftp = False self.verbose = 2 self.timeout = 4 self.memcfg = None # shared memory "XMiR_12345" @@ -658,9 +659,10 @@ class Gateway(): tn = self.get_telnet(verbose) if not tn: return False - ftp = self.get_ftp(verbose) - if not ftp: - return False + if self.use_ftp: + ftp = self.get_ftp(verbose) + if not ftp: + return False return True def run_cmd(self, cmd, msg = None, timeout = None, die_on_error = True): @@ -703,8 +705,8 @@ class Gateway(): if not ret: break else: - cmd = (cmd + '\n').encode('ascii') - tn.write(cmd) + cmd += '\n' + tn.write(cmd.encode('ascii')) tn.read_until(tn.prompt, timeout = 4 if timeout is None else timeout) if not self.use_ssh: tn.write(b"exit\n") @@ -727,11 +729,13 @@ class Gateway(): else: file.write(data) read_size += size - else: + elif self.use_ftp: ftp = self.get_ftp(self.verbose) file = open(fn_local, 'wb') ftp.retrbinary('RETR ' + fn_remote, file.write) file.close() + else: + raise RuntimeError('FIXME') return True def upload(self, fn_local, fn_remote, verbose = 1): @@ -750,9 +754,11 @@ class Gateway(): channel.write(data) size = size + len(data) #except ssh2.exceptions.SCPProtocolError as e: - else: + elif self.use_ftp: ftp = self.get_ftp(self.verbose) ftp.storbinary('STOR ' + fn_remote, file) + else: + raise RuntimeError('FIXME') file.close() return True