def connect (self, host): global connect_timeout if not self.ip_re.match (host): ip = dnsqr.query(host,'A') if ip: # pull out the ip of the first entry ip = ip[0][1] else: # no results found for this entry raise dns_exceptions.DNS_Hard_Error else: ip = host coro.with_timeout (connect_timeout, self.s.connect, (ip, self.ftp_port)) self.read_response ('2')
def connect(self, username, remote_address, remote_port=22, password=None, command=None, debug_level=coro.ssh.util.debug.WARNING): """connect(self, username, remote_address, remote_port=22, password=None, command=None, debug_level=coro.ssh.util.debug.WARNING) -> None The opens a connection to the remote side and authenticates. <username> - The remote username to log into. <remote_address> - The remote address to connect to. <remote_port> - The remote port to connect to. <password> - The password to use when connecting to the remote side. If None, and there are no authorized_keys configured, then it will ask for the password on stdout/stdin. If DISABLE_PASSWORD, will disable password auth. <command> - The command to run on the remote side. If no command is given, then it will open a pty and shell. <debug_level> - Level a debuging to print to stderr. """ self.client = coro.ssh.transport.client.SSH_Client_Transport() if inet_utils.is_ip(remote_address): remote_ip = remote_address hostname = None else: dns_query_result = dnsqr.query(remote_address, 'A') remote_ip = dns_query_result[0][-1] hostname = remote_address coro_socket_transport = coro.ssh.l4_transport.coro_socket_transport self.transport = coro_socket_transport.coro_socket_transport( remote_ip, remote_port, hostname=hostname) self.client.connect(self.transport) self.client.debug.level = debug_level self.service = coro.ssh.connection.connect.Connection_Service( self.client) self._authenticate(username, password) self.channel = coro.ssh.connection.interactive_session.Interactive_Session_Client( self.service) self.channel.open() if command is not None: self.channel.exec_command(command) else: self.channel.open_pty() self.channel.open_shell()
def connect( self, username, remote_address, remote_port=22, password=None, command=None, debug_level=coro.ssh.util.debug.WARNING, ): """connect(self, username, remote_address, remote_port=22, password=None, command=None, debug_level=coro.ssh.util.debug.WARNING) -> None The opens a connection to the remote side and authenticates. <username> - The remote username to log into. <remote_address> - The remote address to connect to. <remote_port> - The remote port to connect to. <password> - The password to use when connecting to the remote side. If None, and there are no authorized_keys configured, then it will ask for the password on stdout/stdin. If DISABLE_PASSWORD, will disable password auth. <command> - The command to run on the remote side. If no command is given, then it will open a pty and shell. <debug_level> - Level a debuging to print to stderr. """ self.client = coro.ssh.transport.client.SSH_Client_Transport() if inet_utils.is_ip(remote_address): remote_ip = remote_address hostname = None else: dns_query_result = dnsqr.query(remote_address, "A") remote_ip = dns_query_result[0][-1] hostname = remote_address coro_socket_transport = coro.ssh.l4_transport.coro_socket_transport self.transport = coro_socket_transport.coro_socket_transport(remote_ip, remote_port, hostname=hostname) self.client.connect(self.transport) self.client.debug.level = debug_level self.service = coro.ssh.connection.connect.Connection_Service(self.client) self._authenticate(username, password) self.channel = coro.ssh.connection.interactive_session.Interactive_Session_Client(self.service) self.channel.open() if command is not None: self.channel.exec_command(command) else: self.channel.open_pty() self.channel.open_shell()