public SshClient doCreateClient(SshConfiguration configuration) { // Much of JSch configuration is global :( configureAlgorithms(configuration); return new JschSshClient(configuration); }
private void doDir(String remotePath, String mode, File sourceFile, OutputStream out, InputStream in) throws IOException { int ack; String basename = Util.basename(remotePath); String command = "D" + (mode == null ? "0755" : mode) + " 0 " + basename; command += "\n"; out.write(command.getBytes()); out.flush(); ack = JschSshClient.checkAck(in); if (ack != 0) { throw new IOException("Incorrect Ack " + ack + " received"); } }
public String getFingerprint() { return getFingerPrint(hash, key); } })) {
public void get(final String remoteFilePath, File targetFile, boolean recursive) throws SshException { SshStreamChannel cmd = sshClient.createCommand("scp -f " + (recursive ? "-r " : "") + remoteFilePath); cmd.open(); int c = JschSshClient.checkAck(in); switch (c) { case 'T': if (JschSshClient.checkAck(in) != 0) { throw new IOException("Incorrect Ack received");
public boolean authenticate(SshAuthenticator[] authenticators) throws SshException { Map authenticatorMap = createAuthenticatorMap(authenticators); SshPasswordAuthenticator paw = (SshPasswordAuthenticator) authenticatorMap.get("password"); SshPublicKeyAuthenticator pk = (SshPublicKeyAuthenticator) authenticatorMap.get("publickey"); SshConfiguration configuration = getConfiguration(); try { session.connect(Integer.parseInt(configuration.getProperties().getProperty(JschSshProvider.CFG_SESSION_CONNECT_TIMEOUT,
public void connect(String username, String hostname, int port) throws SshException { if (isConnected()) { throw new SshException(SshException.NOT_OPEN, "Already connected."); client.setHostKeyRepository(new HostKeyRepositoryBridge(client.getHostKeyRepository())); session = client.getSession(username, hostname, port); final SocketFactory socketFactory = getConfiguration().getSocketFactory(); if (socketFactory != null) { session.setSocketFactory(new com.jcraft.jsch.SocketFactory() { SshConfiguration configuration = getConfiguration();
public boolean isAuthenticated() { return isConnected() && authenticated; }
public void showMessage(String message) { if (getConfiguration().getBannerHandler() != null) { getConfiguration().getBannerHandler().banner(message); } }
+ (verbose ? "-v " : "") + remotePath; SshConfiguration.getLogger().log(Level.INFO, "Executing command '" + command + "'"); SshStreamChannel cmd = sshClient.createCommand(command); try { cmd.open(); OutputStream out = cmd.getOutputStream(); InputStream in = cmd.getInputStream(); int ack = JschSshClient.checkAck(in); if (ack != 0) { throw new IOException("Incorrect Ack " + ack + " received");
public int getRemoteProtocolVersion() { if (!isConnected()) { throw new IllegalStateException("Not connected"); } // Jsch only supports SSH2 return SshConfiguration.SSH2_ONLY; }
public SshExtendedStreamChannel createCommand(String command) throws SshException { try { ChannelExec channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(command); return new JschStreamChannel(getConfiguration(), channel) { protected void onChannelClose() throws SshException { channelCount--; } protected void onChannelOpen() throws SshException { channelCount++; } }; } catch (JSchException e) { throw new SshException("Failed to create shell channel.", e); } }
public void disconnect() throws SshException { if (!isConnected()) { throw new SshException(SshException.NOT_OPEN, "Not connected."); } authenticated = false; try { session.disconnect(); } finally { session = null; } }
public SshShell createShell(String termType, int colWidth, int rowHeight, int pixWidth, int pixHeight, byte[] terminalModes) throws SshException { try { ChannelShell channel = (ChannelShell) session.openChannel("shell"); if (termType != null) { channel.setTerminalMode(terminalModes == null || terminalModes.length == 0 ? new byte[0] : terminalModes); channel.setPtyType(termType, colWidth, rowHeight, pixWidth, pixHeight); } return new JschSshShell(getConfiguration(), channel) { protected void onChannelClose() throws SshException { channelCount--; } protected void onShellOpen() throws SshException { channelCount++; } }; } catch (JSchException e) { throw new SshException("Failed to create shell channel.", e); } }
out.write(command.getBytes()); out.flush(); ack = JschSshClient.checkAck(in); if (ack != 0) { throw new IOException("Incorrect Ack " + ack + " received"); out.write(buf, 0, 1); out.flush(); ack = JschSshClient.checkAck(in); if (ack != 0) { throw new IOException("Incorrect Ack " + ack + " received");
public String getRemoteIdentification() { if (!isConnected()) { throw new IllegalStateException("Not connected"); } // This is required because there is no separate connect / authenticate // phase with JSch if (session.isConnected()) { return session.getServerVersion(); } else { return "Unknown"; } }
public int check(final String host, final byte[] key) { SshHostKeyValidator hostKeyValidator = getConfiguration().getHostKeyValidator(); if (hostKeyValidator != null) { try {