/** * Same as {@link #disconnect()}. * * @throws IOException */ @Override public void close() throws IOException { disconnect(); }
/** * Does key re-exchange. * * @throws TransportException if an error occurs during key exchange */ public void rekey() throws TransportException { doKex(); }
/** On connection establishment, also initializes the SSH transport via {@link Transport#init} and {@link #doKex()}. */ @Override protected void onConnect() throws IOException { super.onConnect(); trans.init(getRemoteHostname(), getRemotePort(), getInputStream(), getOutputStream()); doKex(); }
public SSHClient setupClient(Config config) { if (client == null) { client = new SSHClient(config); client.addHostKeyVerifier(fingerprint); } return client; }
/** * Adds a {@link OpenSSHKnownHosts} object created from the specified location as a host key verifier. * * @param location location for {@code known_hosts} file * * @throws IOException if there is an error loading from any of these locations */ public void loadKnownHosts(File location) throws IOException { addHostKeyVerifier(new OpenSSHKnownHosts(location, loggerFactory)); }
private void checkConnected() { if (!isConnected()) { throw new IllegalStateException("Not connected"); } }
@Override public Session startSession() throws ConnectionException, TransportException { checkConnected(); checkAuthenticated(); final SessionChannel sess = new SessionChannel(conn, remoteCharset); sess.open(); return sess; }
private void checkAuthenticated() { if (!isAuthenticated()) { throw new IllegalStateException("Not authenticated"); } }
/** @return Instantiated {@link SCPFileTransfer} implementation. */ public SCPFileTransfer newSCPFileTransfer() { checkConnected(); checkAuthenticated(); return new SCPFileTransfer(this, loggerFactory); }
/** * Returns a {@link KeyProvider} instance created from a location on the file system where an <em>unencrypted</em> * private key file (does not require a passphrase) can be found. Simply calls {@link #loadKeys(String, * PasswordFinder)} with the {@link PasswordFinder} argument as {@code null}. * * @param location the location for the key file * * @return the key provider ready for use in authentication * * @throws SSHException if there was no suitable key provider available for the file format; typically because * BouncyCastle is not in the classpath * @throws IOException if the key file format is not known, if the file could not be read, etc. */ public KeyProvider loadKeys(String location) throws IOException { return loadKeys(location, (PasswordFinder) null); }
/** Default constructor. Initializes this object using {@link DefaultConfig}. */ public SSHClient() { this(new DefaultConfig()); }
/** @return whether connected. */ @Override public boolean isConnected() { return super.isConnected() && trans.isRunning(); }
public void connect(String hostname) throws IOException { connect(hostname, defaultPort); }
@Override protected Config getClientConfig(DefaultConfig config) { config.setKeyExchangeFactories(Collections.singletonList(clientFactory)); return config; }
@Override public String getNextServiceName() { return nextService.getName(); }
@Override public void notifyError(SSHException error) { super.notifyError(error); authenticated.deliverError(error); }
public void connect(InetAddress host) throws IOException { connect(host, defaultPort); }
@Override public synchronized void setService(Service service) { if (service == null) service = nullService; log.debug("Setting active service to {}", service.getName()); this.service = service; }
/** * Connect to a host via a proxy. * @param hostname The host name to connect to. * @param proxy The proxy to connect via. * @deprecated This method will be removed after v0.12.0. If you want to connect via a proxy, you can do this by injecting a {@link javax.net.SocketFactory} * into the SocketClient. The SocketFactory should create sockets using the {@link java.net.Socket#Socket(java.net.Proxy)} constructor. */ @Deprecated public void connect(String hostname, Proxy proxy) throws IOException { connect(hostname, defaultPort, proxy); }
/** * Connect to a host via a proxy. * @param host The host address to connect to. * @param proxy The proxy to connect via. * @deprecated This method will be removed after v0.12.0. If you want to connect via a proxy, you can do this by injecting a {@link javax.net.SocketFactory} * into the SocketClient. The SocketFactory should create sockets using the {@link java.net.Socket#Socket(java.net.Proxy)} constructor. */ @Deprecated public void connect(InetAddress host, Proxy proxy) throws IOException { connect(host, defaultPort, proxy); }