import os import socket import ssl from xmlrpclib import * class SendFile: def send_file_to_ip(self,ip,remote_auth,local_file,remote_file): try: server = ServerProxy ("https://"+ip+":9779") try: user,password=remote_auth user_info=(user,password) except: # Master Key user_info=remote_auth #request_socket(self,owner,restricted,path=None) port=server.request_socket(user_info,"SocketManager",os.getlogin(),False) #if it's not an integer if type(port)!=type(1): return (False, "Could not request socket: " + port) ret=server.start_socket(user_info,"SocketManager",port) local_file=local_file.encode("utf-8") remote_file=remote_file.encode("utf-8") f=open(local_file,'rb') s=socket.socket() ssl_socket=ssl.wrap_socket(s) ssl_socket.connect((ip,port)) ssl_socket.sendall("[N4D-HEADER-BEGIN]file_path="+remote_file+"[N4D-HEADER-END]"+f.read()) ret_value=True ssl_socket.close() server.close_socket(user_info,"SocketManager",port) return (True,"Success") except Exception as e: print e return(False,"Could not connect to " + ip ) #def send_file #class SendFile