def deluge_add_torrent(ip, port, user, password, torrent_binary): client = DelugeRPCClient(ip, int(port), user, password, decode_utf8=True) client.connect() return client.core.add_torrent_file( filename="", filedump=b64encode(torrent_binary).decode('ascii'), options={})
def connect_ssh(): print("## Establishing SSH connection ##") client = paramiko.SSHClient() #client.get_host_keys().add(upload_host,'ssh-rsa', key) client.load_system_host_keys() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) try: client.connect(upload_host, username=upload_user, password=upload_pw) except paramiko.SSHException: print("ERROR: SSH negotiation failed") print(sys.exc_value) sys.exit(1) except paramiko.AuthenticationException: print ("ERROR: Authentication failed. Please check credentials") print (sys.exc_value) sys.exit(1) except paramiko.BadHostKeyException: print ("ERROR: Bad host key. Check your known_hosts file") print (sys.exc_value) sys.exit(1) except paramiko.PasswordRequiredException: print ("ERROR: Password required. No ssh key in the agent?") print (sys.exc_value) sys.exit(1) except: print ("ERROR: Could not open ssh connection") print (sys.exc_value) sys.exit(1) global ssh ssh = client global sftp sftp = paramiko.SFTPClient.from_transport(client.get_transport()) print ("SSH connection established")
def test_zerorpc(): client = zerorpc.Client() client.connect('tcp://127.0.0.1:7778') print(client.get_songs()) print(client.get_songs(1)) client.add_song('晴天') print(client.get_songs()) client.delete_song('七里香') print(client.get_songs())
def deluge(self, path, torrent_path, torrent, local_path, remote_path, client, meta): client = DelugeRPCClient(client['deluge_url'], int(client['deluge_port']), client['deluge_user'], client['deluge_pass']) # client = LocalDelugeRPCClient() client.connect() if client.connected == True: print("Deluge connected") isdir = os.path.isdir(path) #Remote path mount if local_path in path and local_path != remote_path: path = path.replace(local_path, remote_path) path = path.replace(os.sep, '/') # if isdir == False: else: path = os.path.dirname(path) client.call('core.add_torrent_file', torrent_path, base64.b64encode(torrent.dump()), {'download_location' : path, 'seed_mode' : True}) if meta['debug']: cprint(f"Path: {path}", 'cyan') else: cprint("Unable to connect to deluge", 'grey', 'on_red')
def create_multi_connections(self): for i in range(quantity_user_node_clients): cname = "client" + str(i) t = int(time.time()) client_id = cname + str(t) client = mqtt.Client(client_id) user_node_clients[i]["client"] = client user_node_clients[i]["client_id"] = client_id user_node_clients[i]["cname"] = cname broker = user_node_clients[i]["broker"] port = user_node_clients[i]["port"] try: client.connect(broker, port) except: print("Connection Fialed to broker ", broker) continue client.on_connect = self.on_connect client.on_disconnect = self.on_disconnect client.on_message = self.on_message client.loop_start() while not client.connected_flag: time.sleep(0.05)