def execute_command(self, args): file_name = " ".join(args) send_command(self.conn, "dele {}".format(file_name) + end_msg, self.encoding, self.change_some_code) print(read_response(self.conn, self.encoding, self.change_some_code))
def execute_command(self, args): dir_name = " ".join(args) if args == "..": send_command(self.conn, "cdup" + end_msg, self.encoding, self.change_some_code) print( read_response(self.conn, self.encoding, self.change_some_code)) return send_command(self.conn, "cwd {}".format(dir_name) + end_msg, self.encoding, self.change_some_code) print(read_response(self.conn, self.encoding, self.change_some_code))
def execute_command(self, args): print("user:"******"user {}".format(user_name) + end_msg, self.encoding, self.change_some_code) response = read_response(self.conn, self.encoding, self.change_some_code) if response[0] != "3": print(response) return password = getpass("Enter your password:"******"pass {}".format(password) + end_msg, self.encoding, self.change_some_code) print(read_response(self.conn, self.encoding, self.change_some_code))
def execute_command(self, args): file_name = " ".join(args) ip_and_port = parse_from_response_to_ip_and_port( send_pasv(self.conn, self.encoding)) send_command(self.conn, "stor " + file_name + end_msg, self.encoding, self.change_some_code) with open_connection_at(ip_and_port) as data_connection: response = read_response(self.conn, self.encoding, self.change_some_code) if response[0] != "1": print(response) return send_all_by(data_connection, file_name) print(read_response(self.conn, self.encoding, self.change_some_code))
def execute_command(self, args): file_name = " ".join(args) file_size = self.size_command.execute_command(file_name) if file_size is None: return mode = input("Which mode use? (active, passive)") if mode == 'passive': print('Executing at passive mode') ip_and_port = parse_from_response_to_ip_and_port( send_pasv(self.conn, self.encoding)) send_command(self.conn, "retr {}".format(file_name) + end_msg, self.encoding, self.change_some_code) with open_connection_at(ip_and_port) as data_connection: response = read_response(self.conn, self.encoding, self.change_some_code) if response[0] != "1": print(response) return write_bytes_to_file( file_name, download_all_from(data_connection, int(file_size))) print( read_response(self.conn, self.encoding, self.change_some_code)) else: print('Executing at active mode') server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.bind(("0.0.0.0", 0)) server_socket.listen() ip = get_ip() port = int(server_socket.getsockname()[1]).to_bytes( 2, byteorder='big') send_command( self.conn, f"port {','.join(ip.split('.'))},{port[0]},{port[1]}" + end_msg, self.encoding, self.change_some_code) response = read_response(self.conn, self.encoding, self.change_some_code) if response[0] != '2': print(response) return send_command(self.conn, "retr {}".format(file_name) + end_msg, self.encoding, self.change_some_code) response = read_response(self.conn, self.encoding, self.change_some_code) if response[0] != '1': print(response) return con, addr = server_socket.accept() write_bytes_to_file(file_name, download_all_from(con, int(file_size))) con.close() server_socket.close() print( read_response(self.conn, self.encoding, self.change_some_code))
def execute_command(self, file_name): send_command(self.conn, "size {}".format(file_name) + end_msg, self.encoding, self.change_some_code) size = self.get_file_size() return size