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


Java ClientSession.close方法代码示例

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


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

示例1: receiveFiles

import org.apache.sshd.ClientSession; //导入方法依赖的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

示例2: shutdown

import org.apache.sshd.ClientSession; //导入方法依赖的package包/类
public void shutdown() throws StartException {
	try {
		for(ClientSession session : clientSessions) {
			session.close(false);
		}
		client.stop();
		sshd.stop();
	} catch (InterruptedException e) {
		throw new StartException("Failed to stop SshServer", e);
	}
}
 
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:12,代码来源:Start.java

示例3: createConnection

import org.apache.sshd.ClientSession; //导入方法依赖的package包/类
protected AgentConnection createConnection(Agent agent, SshConnectionOptions opts) throws IOException, InterruptedException {
    SshClient client = getClient();
    ClientSession session = null;
    boolean success = false;
    try {
        session = connect(client, opts);
        String hostIp = getIp(opts);

        String script = copyBootStrap(session);
        int port = setForwarding(session);
        log.info("Allocated random port [{}] on [{}]", port, opts.getHost());
        EofAwareChannelExec exec = callBootStrap(agent, session, String.format("%s --read-env --port %d --ip %s", script, port, hostIp));

        final SshAgentConnection sshAgent = new SshAgentConnection(agent.getId(), agent.getUri(), eventService, this, session, exec, port);
        success = true;
        connections.add(sshAgent);

        exec.onEof(new Runnable() {
            @Override
            public void run() {
                sshAgent.close();
            }
        });

        CloseListener listener = new CloseListener(sshAgent);
        session.addListener(listener);
        OpenFuture execOpen = exec.open();

        execOpen.addListener(listener);

        try {
            execOpen.await(SSH_TIMEOUT.get(), TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            throw new IllegalStateException("Interrupted waiting for script [" + script + "]", e);
        }

        if ( ! execOpen.isOpened() ) {
            throw new IOException("Failed to start script [" + script + "]");
        }

        success = writeAuth(sshAgent);
        if ( ! success ) {
            sshAgent.close();
            throw new IOException("Failed to write context info for agent [" + sshAgent.getAgentId() + "]");
        }

        return sshAgent;
    } finally {
        if ( ! success && session != null ) {
            session.close(true);
        }
    }
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:54,代码来源:SshAgentConnectionFactory.java

示例4: createConnection

import org.apache.sshd.ClientSession; //导入方法依赖的package包/类
protected AgentConnection createConnection(Agent agent, SshConnectionOptions opts) throws IOException, InterruptedException {
    SshClient client = getClient();
    ClientSession session = null;
    boolean success = false;
    try {
        session = connect(client, opts);
        String hostIp = getIp(opts);

        String script = copyBootStrap(session);
        int port = setForwarding(session);
        log.info("Allocated random port [{}] on [{}]", port, opts.getHost());
        EofAwareChannelExec exec = callBootStrap(agent, session, String.format("%s --port %d --ip %s", script, port, hostIp));

        final SshAgentConnection sshAgent = new SshAgentConnection(agent.getId(), agent.getUri(), eventService, this, session, exec, port);
        success = true;
        connections.add(sshAgent);

        exec.onEof(new Runnable() {
            @Override
            public void run() {
                sshAgent.close();
            }
        });

        CloseListener listener = new CloseListener(sshAgent);
        session.addListener(listener);
        OpenFuture execOpen = exec.open();

        execOpen.addListener(listener);

        try {
            execOpen.await(SSH_TIMEOUT.get(), TimeUnit.MILLISECONDS);
        } catch (InterruptedException e) {
            throw new IllegalStateException("Interrupted waiting for script [" + script + "]", e);
        }

        if ( ! execOpen.isOpened() ) {
            throw new IOException("Failed to start script [" + script + "]");
        }

        success = writeAuth(sshAgent);
        if ( ! success ) {
            sshAgent.close();
            throw new IOException("Failed to write context info for agent [" + sshAgent.getAgentId() + "]");
        }

        return sshAgent;
    } finally {
        if ( ! success && session != null ) {
            session.close(true);
        }
    }
}
 
开发者ID:ibuildthecloud,项目名称:dstack,代码行数:54,代码来源:SshAgentConnectionFactory.java


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