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


Java SSHClient.disconnect方法代码示例

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


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

示例1: uploadFile

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void uploadFile() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
  final SSHClient ssh = new SSHClient();
  ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));

  ssh.connect("localhost", subject.getPort());
  try {
    ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
        KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));

    final SFTPClient sftp = ssh.newSFTPClient();
    File testFile = local.newFile("fred.txt");
    try {
      sftp.put(new FileSystemFile(testFile), "/fred.txt");
    } finally {
      sftp.close();
    }
  } finally {
    ssh.disconnect();
  }

  assertThat(sftpHome.getRoot().list(), is(new String[]{"fred.txt"}));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:24,代码来源:TestSftpRule.java

示例2: executeCommand

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public String executeCommand(ShellCommand aCommand) throws IOException {
    SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();
    ssh.connect("localhost", 2222);
    try {
        ssh.authPublickey("root");
        try (Session session = ssh.startSession()) {
            Session.Command command = session.exec(aCommand.getCommand());
            String text = IOUtils.readFully(command.getInputStream()).toString();
            command.join(5, TimeUnit.SECONDS);
            return text;
        }
    } finally {
        ssh.disconnect();
    }
}
 
开发者ID:evsinev,项目名称:docker-network-veth,代码行数:18,代码来源:CommandServiceSsh.java

示例3: 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

示例4: runCommand

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public RemoteProcess runCommand(List<String> command) throws InterruptedException, IOException {
  SSHClient ssh;
  ssh = connectWithSSH();
  try {
    ProcessAdapter process = runCommandAndWrapInProcessAdapter(command, ssh);
    process.run();
    process.waitFor();
    return process;
  } catch (InterruptedException | IOException e) {
    try {
      ssh.disconnect();
    } catch (IOException ioException) {
      LOGGER.warn("runCommand(): Could not disconnect ssh.", ioException);
    }
    throw e;
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:19,代码来源:SSHEnvironment.java

示例5: connect_to_virtual_box

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void connect_to_virtual_box() throws IOException {
    SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();
    ssh.connect("localhost", 2222);
    try {
        ssh.authPublickey("root");
        try (Session session = ssh.startSession()) {
            Session.Command command = session.exec("ls -l");
            System.out.println(IOUtils.readFully(command.getInputStream()).toString());
            command.join(5, TimeUnit.SECONDS);
        }
    } finally {
        ssh.disconnect();
    }

}
 
开发者ID:evsinev,项目名称:docker-network-veth,代码行数:18,代码来源:SshClientTest.java

示例6: 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

示例7: 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

示例8: 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

示例9: 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

示例10: downloadFile

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Test
public void downloadFile() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
  FileUtils.write(sftpHome.newFile("fred.txt"), "Electric boogaloo");

  final SSHClient ssh = new SSHClient();
  ssh.addHostKeyVerifier(SecurityUtils.getFingerprint(subject.getHostsPublicKey()));

  ssh.connect("localhost", subject.getPort());
  try {
    ssh.authPublickey("this_is_ignored", new KeyPairWrapper(
        KeyPairGenerator.getInstance("DSA", "SUN").generateKeyPair()));

    final SFTPClient sftp = ssh.newSFTPClient();

    try {
      sftp.get("fred.txt", new FileSystemFile(new File(local.getRoot(), "fred.txt")));
    } finally {
      sftp.close();
    }
  } finally {
    ssh.disconnect();
  }

  assertThat(FileUtils.readFileToString(new File(local.getRoot(), "fred.txt")),
      is("Electric boogaloo"));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:27,代码来源:TestSftpRule.java

示例11: listFiles

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
/**
 * Override listFiles() method to share the ssh client among the different executed commands
 */
@Override
public Set<FileInfo> listFiles(String logAccessConfigId, String subPath) throws LogAccessException {
	
	// Get the LogAccessConfig
	LogAccessConfig logAccessConfig = configService.getLogAccessConfig(logAccessConfigId);

	// Create ssh client, authenticate and put it into thread local for a shared use
	SSHClient sshClient = connectAndAuthenticate(logAccessConfig);
	sshClientThreadLocal.set(sshClient);

	// List files using prepared ssh client
	try {
		return super.listFiles(logAccessConfigId, subPath);
	}
	finally {
		sshClientThreadLocal.remove();
		try {
			sshClient.disconnect();
		} catch (IOException e) {}
	}
}
 
开发者ID:fbaligand,项目名称:lognavigator,代码行数:25,代码来源:SshLogAccessService.java

示例12: downloadFile

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public void downloadFile(String logAccessConfigId, String fileName, OutputStream downloadOutputStream) throws LogAccessException {
	
	// Get the LogAccessConfig
	LogAccessConfig logAccessConfig = configService.getLogAccessConfig(logAccessConfigId);
	
	// Create ssh client and authenticate
	SSHClient sshClient = connectAndAuthenticate(logAccessConfig);

	// Execute the download
	try {
		String filePath = fileName.startsWith("/") ? fileName : logAccessConfig.getDirectory() + "/" + fileName;
		sshClient.newSCPFileTransfer().download(filePath, new ScpStreamingSystemFile(downloadOutputStream));
	}
	catch (IOException e) {
		throw new LogAccessException("Error when executing downloading " + fileName + " on " + logAccessConfig, e);
	}
	finally {
           try {
			sshClient.disconnect();
		}
           catch (IOException ioe) {}
	}
	
}
 
开发者ID:fbaligand,项目名称:lognavigator,代码行数:26,代码来源:SshLogAccessService.java

示例13: copyFilesFromLocalDisk

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public void copyFilesFromLocalDisk(Path srcPath, String destRelPath) throws IOException {
  LOGGER.trace("copyFilesFromLocalDisk({}, {})", srcPath.toString(), destRelPath);
  mkdirs(destRelPath);

  // Must be correct, because mkdirs has passed.
  String remotePath = concatenatePathToHome(destRelPath);

  SSHClient ssh = connectWithSSH();
  try {
    ssh.useCompression();

    ssh.newSCPFileTransfer().upload(new FileSystemFile(srcPath.toFile()), remotePath);
  } finally {
    ssh.disconnect();
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:18,代码来源:SSHEnvironment.java

示例14: copyFilesToLocalDisk

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public void copyFilesToLocalDisk(String srcRelPath, Path destPath) throws IOException {
  LOGGER.trace("copyFilesToLocalDisk({}, {})", srcRelPath, destPath.toString());
  createDestinationDirectoriesLocally(destPath);

  SSHClient ssh = connectWithSSH();
  try {
    ssh.useCompression();

    String remotePath = concatenatePathToHome(srcRelPath);

    ssh.newSCPFileTransfer().download(remotePath, new FileSystemFile(destPath.toFile()));
  } finally {
    ssh.disconnect();
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:17,代码来源:SSHEnvironment.java

示例15: runCommandAsynchronously

import net.schmizz.sshj.SSHClient; //导入方法依赖的package包/类
@Override
public RemoteProcess runCommandAsynchronously(List<String> command) throws IOException {
  SSHClient ssh;
  ssh = connectWithSSH();
  try {
    ProcessAdapter process = runCommandAndWrapInProcessAdapter(command, ssh);
    mExecutor.execute(process);
    return process;
  } catch (IOException e) {
    try {
      ssh.disconnect();
    } catch (IOException ioException) {
      LOGGER.warn("runCommandAsynchronously(): Could not disconnect ssh.", ioException);
    }
    throw e;
  }
}
 
开发者ID:gregorias,项目名称:dfuntest,代码行数:18,代码来源:SSHEnvironment.java


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