本文整理汇总了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"}));
}
示例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"));
}
示例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;
}
示例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"));
}
示例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;
}