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


Java SFTPClient.close方法代码示例

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


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

示例1: uploadFile

import net.schmizz.sshj.sftp.SFTPClient; //导入方法依赖的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: downloadFile

import net.schmizz.sshj.sftp.SFTPClient; //导入方法依赖的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

示例3: getTempLocalInstance

import net.schmizz.sshj.sftp.SFTPClient; //导入方法依赖的package包/类
public File getTempLocalInstance( String remoteFilePath )
{
  File tempFile = null;
  SSHClient client = new SSHClient();
  // required if host is not in knownLocalHosts
  client.addHostKeyVerifier(new PromiscuousVerifier());

  try {
    client.connect(hostName);
    client.authPassword(userName, userPass);

    tempFile = File.createTempFile("tmp", null, null);
    tempFile.deleteOnExit();

    SFTPClient sftp = client.newSFTPClient();
    sftp.get(remoteFilePath, new FileSystemFile(tempFile));
    sftp.close();
    client.disconnect();

  } catch( Exception e ) { 
    //TODO: this needs to be more robust than just catching all exceptions
    e.printStackTrace();
    logger.error( e.toString() );
    return null;
  } 
  
  return tempFile;
}
 
开发者ID:prateek,项目名称:ssh-spool-source,代码行数:29,代码来源:SshClientJ.java

示例4: listFiles

import net.schmizz.sshj.sftp.SFTPClient; //导入方法依赖的package包/类
@Test
public void listFiles() throws IOException, NoSuchProviderException, NoSuchAlgorithmException {
  sftpHome.newFile("fred.txt");
  List<RemoteResourceInfo> files;

  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 {
      files = sftp.ls("/");
    } finally {
      sftp.close();
    }
  } finally {
    ssh.disconnect();
  }

  assertThat(files.size(), is(1));
  assertThat(files.get(0).getName(), is("fred.txt"));
}
 
开发者ID:mlk,项目名称:AssortmentOfJUnitRules,代码行数:28,代码来源:TestSftpRule.java

示例5: getFilesInPath

import net.schmizz.sshj.sftp.SFTPClient; //导入方法依赖的package包/类
public ArrayList< String > getFilesInPath( String path ) 
{
  ArrayList< String > ret = new ArrayList< String >();

  SSHClient client = new SSHClient();
  client.addHostKeyVerifier(new PromiscuousVerifier());

  try {
    client.connect(hostName);
    client.authPassword(userName, userPass);

    SFTPClient sftp                  = client.newSFTPClient();
    List< RemoteResourceInfo > files = sftp.ls( path );
    for( RemoteResourceInfo file: files )
    {
      ret.add( file.getPath() );
    }

    sftp.close();
    client.disconnect();

  } catch( Exception e ) {
    logger.error( e.toString() );
  } 

  return ret;
}
 
开发者ID:prateek,项目名称:ssh-spool-source,代码行数:28,代码来源:SshClientJ.java


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