本文整理汇总了Java中org.apache.sshd.client.future.ConnectFuture类的典型用法代码示例。如果您正苦于以下问题:Java ConnectFuture类的具体用法?Java ConnectFuture怎么用?Java ConnectFuture使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ConnectFuture类属于org.apache.sshd.client.future包,在下文中一共展示了ConnectFuture类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: connectWithRetries
import org.apache.sshd.client.future.ConnectFuture; //导入依赖的package包/类
private static ClientSession connectWithRetries(SshClient client, ClientConfig config) throws Exception, InterruptedException {
ClientSession session = null;
int retries = 0;
do {
try {
ConnectFuture future = client.connect(config.getUser(), config.getHost(), config.getPort());
future.await();
session = future.getSession();
} catch (RuntimeSshException ex) {
if (++retries < 10) {
TimeUnit.SECONDS.sleep(2);
} else {
throw ex;
}
}
} while (session == null);
return session;
}
开发者ID:Talend,项目名称:tesb-studio-se,代码行数:19,代码来源:RuntimeClient.java
示例2: receiveFiles
import org.apache.sshd.client.future.ConnectFuture; //导入依赖的package包/类
@Override
public void receiveFiles(TransferJob job) throws FileNotFoundException, Exception {
log.debug("Receiving files from {}",job.getSourceUrl());
// TODO error handle URI parsing.
final URI url = new URI(job.getSourceUrl());
final String hostname = url.getHost();
final int port = url.getPort() != -1 ? url.getPort() : 22;
final String path = url.getPath();
ConnectFuture connectFuture = sshClient.connect(job.getSourceUsername(), hostname, port);
ClientSession session = connectFuture.await().getSession();
session.addPasswordIdentity(job.getSourcePassword());
session.auth().await();
SftpClient sftpClient = session.createSftpClient();
for(DirEntry dirEntry : sftpClient.readDir(path)){
if( dirEntry.attributes.isRegularFile()
&& FilenameUtils.wildcardMatch(dirEntry.filename, job.getSourceFilepattern())){
queueFile(dirEntry,path,sftpClient,job);
}
}
sftpClient.close();
session.close(false);
}
开发者ID:northlander,项目名称:activemft,代码行数:28,代码来源:SftpReceiver.java
示例3: sendFile
import org.apache.sshd.client.future.ConnectFuture; //导入依赖的package包/类
@Override
public void sendFile(Message msg, TransferJob job, TransferEvent event) {
try {
final String filename = msg.getStringProperty("filename");
final URI url = new URI(job.getTargetUrl());
final String hostname = url.getHost();
final int port = url.getPort() != -1 ? url.getPort() : 22;
final String path = url.getPath();
ConnectFuture connectFuture = sshClient.connect(job.getTargetUsername(), hostname, port);
ClientSession session = connectFuture.await().getSession();
session.addPasswordIdentity(job.getTargetPassword());
session.auth().await();
SftpClient sftpClient = session.createSftpClient();
// TODO make it possible to rename the file according to some generic pattern.
//job.getTargetFilename() + RandomStringUtils.randomAlphanumeric(5);
log.debug("Saving file to SFTP: {}, job: {}", hostname + ":" + port + path + "/" + filename, job.getName() + "(" + job.getId() + ")");
OutputStream os = sftpClient.write(path + "/" + filename);
BufferedOutputStream bos = new BufferedOutputStream(os);
// This will block until the entire content is saved on disk
msg.setObjectProperty("JMS_AMQ_SaveStream", bos);
bos.close();
os.close();
event.setState("done");
event.setTimestamp(new DateTime());
event = eventRepo.saveAndFlush(event);
log.debug("File saved to SFTP: {}, job: {}", path + "/" + filename, job.getName() + "(" + job.getId() + ")");
} catch (Exception e) {
event.setState("send failed");
event.setTimestamp(new DateTime());
event = eventRepo.save(event);
log.warn("Error sending file {}, job: {}", event.getFilename(), job.getName() + "(" + job.getId() + ")");
log.warn("Error descr", e);
throw new RuntimeException("Rollback SFTP transaction");
}
}
开发者ID:northlander,项目名称:activemft,代码行数:40,代码来源:SftpSender.java
示例4: startSession
import org.apache.sshd.client.future.ConnectFuture; //导入依赖的package包/类
@Deprecated
private void startSession() throws IOException {
final ConnectFuture connectFuture;
connectFuture = client.connect(deviceInfo.name(),
deviceInfo.ip().toString(),
deviceInfo.port())
.verify(connectTimeout, TimeUnit.SECONDS);
session = connectFuture.getSession();
//Using the device ssh key if possible
if (deviceInfo.getKey() != null) {
try (PEMParser pemParser = new PEMParser(new CharArrayReader(deviceInfo.getKey()))) {
JcaPEMKeyConverter converter = new JcaPEMKeyConverter().setProvider(BouncyCastleProvider.PROVIDER_NAME);
try {
KeyPair kp = converter.getKeyPair((PEMKeyPair) pemParser.readObject());
session.addPublicKeyIdentity(kp);
} catch (IOException e) {
throw new NetconfException("Failed to authenticate session with device " +
deviceInfo + "check key to be a valid key", e);
}
}
} else {
session.addPasswordIdentity(deviceInfo.password());
}
session.auth().verify(connectTimeout, TimeUnit.SECONDS);
Set<ClientSession.ClientSessionEvent> event = session.waitFor(
ImmutableSet.of(ClientSession.ClientSessionEvent.WAIT_AUTH,
ClientSession.ClientSessionEvent.CLOSED,
ClientSession.ClientSessionEvent.AUTHED), 0);
if (!event.contains(ClientSession.ClientSessionEvent.AUTHED)) {
log.debug("Session closed {} {}", event, session.isClosed());
throw new NetconfException("Failed to authenticate session with device " +
deviceInfo + "check the user/pwd or key");
}
openChannel();
}
开发者ID:opennetworkinglab,项目名称:onos,代码行数:37,代码来源:NetconfSessionMinaImpl.java
注:本文中的org.apache.sshd.client.future.ConnectFuture类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论