当前位置: 首页>>代码示例>>Java>>正文


Java SSHClient.close方法代码示例

本文整理汇总了Java中net.schmizz.sshj.SSHClient.close方法的典型用法代码示例。如果您正苦于以下问题:Java SSHClient.close方法的具体用法?Java SSHClient.close怎么用?Java SSHClient.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.schmizz.sshj.SSHClient的用法示例。


在下文中一共展示了SSHClient.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectfromPItoServer

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public static void connectfromPItoServer(int fotosAnzahl, int belichtungsDauer)
            throws IOException {
    	final String ipServer = Inet4Address.getLocalHost().getHostAddress();
//    	System.out.println(Inet4Address.getAllByName("raspberrypi"));
//    	System.out.println(fotosAnzahl);
        final SSHClient ssh = new SSHClient();
        ssh.addHostKeyVerifier(new NullHostKeyVerifier());
//        for(int i = 0; i < InetAddress.)
//        ssh.connect("192.168.2.100", 22);
        ssh.connect(Settings.raspberryIP, 22);
       
        try {
         ssh.authPassword("pi", "raspberry");
            final Session session = ssh.startSession();
            try {
            	System.out.println("BEGINNE MIt tray");
                final Command cmd = session.exec("java -jar Desktop/Driver/Java/client.jar " + fotosAnzahl + " " + ipServer + " " + belichtungsDauer);
                System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
                cmd.join(5, TimeUnit.SECONDS);
                System.out.println("\n** exit status: " + cmd.getExitStatus());
            } finally {
                session.close();
            }
        } finally {
            ssh.disconnect();
            ssh.close();
        }
    }
 
开发者ID:Raldir,项目名称:3DScanner.RaspberryPi,代码行数:29,代码来源:Exec.java

示例2: testAllHMAC

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void testAllHMAC() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch");
    final SFTPSession session = new SFTPSession(host);
    final DefaultConfig defaultConfig = new DefaultConfig();
    defaultConfig.setMACFactories(
        new HMACSHA2256.Factory(),
        new HMACSHA2512.Factory()
    );
    for(net.schmizz.sshj.common.Factory.Named<MAC> mac : defaultConfig.getMACFactories()) {
        final DefaultConfig configuration = new DefaultConfig();
        configuration.setMACFactories(Collections.singletonList(mac));
        final SSHClient client = session.connect(new DisabledHostKeyCallback(), configuration);
        assertTrue(client.isConnected());
        client.close();
    }
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:18,代码来源:SFTPSessionTest.java

示例3: receiveFile

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public void receiveFile(String lfile, String rfile) throws Exception {
	final SSHClient ssh = getConnectedClient();

	try {
		final Session session = ssh.startSession();
		try {
			ssh.newSCPFileTransfer().download(rfile, new FileSystemFile(lfile));
		} catch (SCPException e) {
			if (e.getMessage().contains("No such file or directory"))
				logger.warn("No file or directory `{}` found on {}.", rfile, ip);
			else
				throw e;
		} finally {
			session.close();
		}
	} finally {
		ssh.disconnect();
		ssh.close();
	}
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:21,代码来源:Sshj.java

示例4: scpUpload

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
/**
 * Upload one or more files via the same SSH/SCP connection to a remote host.
 */
public static void scpUpload(HostInfo hostInfo, List<FromTo> fromTos) throws IOException {
    SSHClient ssh = getSshClient(hostInfo);

    try {
        Session session = ssh.startSession();
        session.allocateDefaultPTY();
        try {
            for (FromTo ft: fromTos) {
                System.out.format("SCP cp %s -> %s/%s%n", ft.from, hostInfo.host, ft.to);
                ssh.newSCPFileTransfer().upload(ft.from, ft.to);
            }
        } finally {
            session.close();
        }
    } finally {
        ssh.disconnect();
        ssh.close();
    }
}
 
开发者ID:electronicarts,项目名称:gatling-aws-maven-plugin,代码行数:23,代码来源:SshClient.java

示例5: scpDownload

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public static void scpDownload(HostInfo hostInfo, FromTo fromTo) throws IOException {
    SSHClient ssh = getSshClient(hostInfo);

    try {
        Session session = ssh.startSession();
        session.allocateDefaultPTY();
        try {
            ssh.newSCPFileTransfer().download(fromTo.from, fromTo.to);
        } finally {
            session.close();
        }
    } finally {
        ssh.disconnect();
        ssh.close();
    }
}
 
开发者ID:electronicarts,项目名称:gatling-aws-maven-plugin,代码行数:17,代码来源:SshClient.java

示例6: executeCommand

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public static int executeCommand(HostInfo hostInfo, String command, boolean debugOutputEnabled) throws IOException {
    SSHClient ssh = getSshClient(hostInfo);

    try {
        Session session = ssh.startSession();
        session.allocateDefaultPTY();
        try {
            if (debugOutputEnabled) {
                System.out.println("About to run: " + command);
            }
            Command cmd = session.exec(command);
            readCommandOutput(cmd);
            cmd.join();
            printExitCode(cmd.getExitStatus());
            return cmd.getExitStatus();
        } finally {
            session.close();
        }
    } finally {
        ssh.disconnect();
        ssh.close();
    }
}
 
开发者ID:electronicarts,项目名称:gatling-aws-maven-plugin,代码行数:24,代码来源:SshClient.java

示例7: doInBackground

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
protected Boolean doInBackground(String... cmd) {
	String ssh_command = cmd[0];
	SSHClient ssh = new SSHClient();
	HostKeyVerifier always_verify = new HostKeyVerifier() {
				public boolean verify(String arg0, int arg1, PublicKey arg2) {
					return true;
				}  
	}; 
	ssh.addHostKeyVerifier(always_verify);  
	Boolean success = false;
	try {
		ssh.connect(this.ssh_server);
		ssh.authPassword(this.ssh_user, this.ssh_password);
		Session session = ssh.startSession();
		Command command = session.exec(ssh_command);
		command.join();
		Integer exit_status = command.getExitStatus(); 
		if (exit_status == this.expected_exit_status) {
			success = true;
		}
		session.close();
		ssh.close();
	} catch (IOException e) { }
	return success;
}
 
开发者ID:hkparker,项目名称:ComputerManager,代码行数:27,代码来源:BackgroundSSHExec.java

示例8: assertSshCommand

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
private void assertSshCommand(Machine machine, AdminAccess adminAccess, String bashCommand) throws IOException {
    LOG.info("Checking return code for command '{}' on machine {}", bashCommand, machine.getExternalId());
    SSHClient client = Ssh.newClient(machine, adminAccess);
    try {
        Session session = client.startSession();
        try {
            session.allocateDefaultPTY();
            Session.Command command = session.exec(bashCommand);

            command.join();
            assertTrue("Exit code was " + command.getExitStatus() + " for command " + bashCommand,
                command.getExitStatus() == 0);
        } finally {
            session.close();
        }
    } finally {
        client.close();
    }
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:20,代码来源:AmazonProvisionrLiveTest.java

示例9: testConnectToLocalhostAndCollectOutput

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void testConnectToLocalhostAndCollectOutput() throws IOException {
    SSHClient client = Ssh.newClient(localhost, adminAccess, 1000);
    try {
        Session session = client.startSession();
        try {
            final Session.Command command = session.exec("echo 'stdout' && echo 'stderr' 1>&2");

            String stdout = CharStreams.toString(new InputStreamReader(command.getInputStream()));
            String stderr = CharStreams.toString(new InputStreamReader(command.getErrorStream()));

            command.join();
            assertThat(command.getExitStatus()).isEqualTo(0);
            assertThat(command.getExitErrorMessage()).isNull();

            assertThat(stdout).contains("stdout");
            assertThat(stderr).contains("stderr");

        } finally {
            session.close();
        }
    } finally {
        client.close();
    }
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:26,代码来源:SshLiveTest.java

示例10: testAES256CTRCipher

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void testAES256CTRCipher() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch");
    final SFTPSession session = new SFTPSession(host);
    final DefaultConfig configuration = new DefaultConfig();
    configuration.setCipherFactories(Collections.singletonList(new AES256CTR.Factory()));
    final SSHClient client = session.connect(new DisabledHostKeyCallback(), configuration);
    assertTrue(client.isConnected());
    client.close();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:11,代码来源:SFTPSessionTest.java

示例11: testECDHNistPKeyExchange

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void testECDHNistPKeyExchange() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch");
    final SFTPSession session = new SFTPSession(host);
    final DefaultConfig configuration = new DefaultConfig();
    configuration.setKeyExchangeFactories(Collections.singletonList(new ECDHNistP.Factory256()));
    final SSHClient client = session.connect(new DisabledHostKeyCallback(), configuration);
    assertTrue(client.isConnected());
    client.close();
}
 
开发者ID:iterate-ch,项目名称:cyberduck,代码行数:11,代码来源:SFTPSessionTest.java

示例12: sendFile

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public void sendFile(String lfile, String rfile) throws Exception {
	final SSHClient ssh = getConnectedClient();

	try {
		final Session session = ssh.startSession();
		try {
			ssh.newSCPFileTransfer().upload(new FileSystemFile(lfile), rfile);
		} finally {
			session.close();
		}
	} finally {
		ssh.disconnect();
		ssh.close();
	}
}
 
开发者ID:rickdesantis,项目名称:cloud-runner,代码行数:16,代码来源:Sshj.java

示例13: main

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
public static void main(String[] args) throws IOException {
    SSHClient ssh = new SSHClient();
    ssh.addHostKeyVerifier(
            new HostKeyVerifier() {
                @Override
                public boolean verify(String s, int i, PublicKey publicKey) {
                    return true;
                }
            });
    ssh.connect("sdf.org");
    ssh.authPassword("new", "");
    Session session = ssh.startSession();
    session.allocateDefaultPTY();
    Shell shell = session.startShell();
    Expect expect = new ExpectBuilder()
            .withOutput(shell.getOutputStream())
            .withInputs(shell.getInputStream(), shell.getErrorStream())
            .withEchoInput(System.out)
            .withEchoOutput(System.err)
            .withInputFilters(removeColors(), removeNonPrintable())
            .withExceptionOnFailure()
            .build();
    try {
        expect.expect(contains("[RETURN]"));
        expect.sendLine();
        String ipAddress = expect.expect(regexp("Trying (.*)\\.\\.\\.")).group(1);
        System.out.println("Captured IP: " + ipAddress);
        expect.expect(contains("login:"));
        expect.sendLine("new");
        expect.expect(contains("(Y/N)"));
        expect.send("N");
        expect.expect(regexp(": $"));
        expect.send("\b");
        expect.expect(regexp("\\(y\\/n\\)"));
        expect.sendLine("y");
        expect.expect(contains("Would you like to sign the guestbook?"));
        expect.send("n");
        expect.expect(contains("[RETURN]"));
        expect.sendLine();
    } finally {
        expect.close();
        session.close();
        ssh.close();
    }
}
 
开发者ID:Alexey1Gavrilov,项目名称:ExpectIt,代码行数:46,代码来源:SshJExample.java

示例14: testCreateFileOverSsh

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void testCreateFileOverSsh() throws IOException {
    SSHClient client = Ssh.newClient(localhost, adminAccess, 1000);
    try {
        String destination = "/tmp/" + UUID.randomUUID().toString();
        String content = UUID.randomUUID().toString();

        Ssh.createFile(client, content, 0600, destination);

        /* Check the file exists and has the expected content */
        Session session = client.startSession();
        try {
            final Session.Command command = session.exec("set +x +e && cat " + destination);

            String output = CharStreams.toString(new InputStreamReader(command.getInputStream()));
            command.join();

            assertThat(command.getExitStatus()).isEqualTo(0);
            assertThat(output).contains(content);

        } finally {
            session.close();
        }
    } finally {
        client.close();
    }

}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:29,代码来源:SshLiveTest.java

示例15: execute

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public void execute(DelegateExecution execution) throws IOException {
    Pool pool = (Pool) execution.getVariable(CoreProcessVariables.POOL);
    checkNotNull(pool, "Please add the pool description as a process " +
        "variable with the name '%s'.", CoreProcessVariables.POOL);

    Machine machine = (Machine) execution.getVariable("machine");
    checkNotNull(machine, "expecting a process variable named 'machine'");

    LOG.info(">> Connecting to machine {} to run puppet script", machine);

    SSHClient client = Ssh.newClient(machine, overrideAdminAccess(pool));
    try {
        for (Map.Entry<String, String> entry : createAdditionalFiles(pool, machine).entrySet()) {
            Ssh.createFile(client, /* content = */ entry.getValue(), 0600, /* destination= */ entry.getKey());
        }

        final String destination = "/tmp/" + remoteFileName + ".pp";
        Ssh.createFile(client, createPuppetScript(pool, machine), 0600, destination);

        Session session = client.startSession();
        try {
            session.allocateDefaultPTY();

            // TODO: extract this loop outside of this activity (probably using a business process error)
            final String runScriptWithWaitCommand = "while ! which puppet &> /dev/null ; " +
                "do echo 'Puppet command not found. Waiting for userdata.sh script to finish (10s)' " +
                "&& sleep 10; " +
                "done " +
                "&& sudo puppet apply --detailed-exitcodes --debug --verbose " + destination;
            Session.Command command = session.exec(runScriptWithWaitCommand);

            Ssh.logCommandOutput(LOG, machine.getExternalId(), command);
            command.join();

            final Integer exitStatus = command.getExitStatus();
            if (exitStatus != PUPPET_FINISHED_WITH_NO_FAILURES && exitStatus != 0) {
                throw new RuntimeException(String.format("Failed to execute puppet. " +
                    "Exit code: %d. Exit message: %s", exitStatus, command.getExitErrorMessage()));

            } else {
                LOG.info("<< Command completed successfully with exit code 0");
            }


        } finally {
            session.close();
        }
    } finally {
        client.close();
    }
}
 
开发者ID:apache,项目名称:incubator-provisionr,代码行数:53,代码来源:PuppetActivity.java


注:本文中的net.schmizz.sshj.SSHClient.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。