• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java ClientSession类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: copyBootStrap

import org.apache.sshd.ClientSession; //导入依赖的package包/类
protected String copyBootStrap(ClientSession session) throws IOException {
    String dest = BOOTSTRAP_FILE.get() + random.nextLong();
    SftpClient sftpClient = session.createSftpClient();
    try {
        Handle handle = sftpClient.open(dest, EnumSet.of(OpenMode.Read, OpenMode.Write, OpenMode.Create, OpenMode.Exclusive));
        Attributes attr = new Attributes().perms(0700);
        sftpClient.setStat(handle, attr);
        byte[] content = BootstrapScript.getBootStrapSource();
        sftpClient.write(handle, 0, content, 0, content.length);
        sftpClient.close(handle);

        return dest;
    } finally {
        if ( sftpClient != null ) {
            sftpClient.close();
        }
    }
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:19,代码来源:SshAgentConnectionFactory.java


示例2: SSHWindow

import org.apache.sshd.ClientSession; //导入依赖的package包/类
/**
 * The constructor for the SSH window
 * 
 * @param app The main application to which this window should be attached
 * @param session The current SSH session
 * @param width The width of the window
 * @param height The height of the window
 */
public SSHWindow(ClientSession session, int width, int height) {
	setCaption("SSH");
	setImmediate(true);
	setResizable(false);
	setWidth("" + width + "px");
	setHeight(""+ height + "px");
	
	VerticalLayout vPanel = new VerticalLayout();
	vPanel.setWidth("100%");
	vPanel.setHeight("100%");
	
	if (session != null) {
		terminal = new SSHTerminal(this, session, TERM_WIDTH, TERM_HEIGHT);
		vPanel.addComponent(terminal);
		vPanel.setComponentAlignment(terminal, Alignment.TOP_CENTER);
	} else {
		vPanel.addComponent(errorLabel);
		vPanel.setComponentAlignment(errorLabel, Alignment.MIDDLE_CENTER);
	}
	addComponent(vPanel);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:30,代码来源:SSHWindow.java


示例3: SSHTerminal

import org.apache.sshd.ClientSession; //导入依赖的package包/类
/**
 * Constructor for the SSH Terminal 
 * @param app The main application
 * @param sshWindow The window holding the terminal
 * @param session The client instance used in the authorization of user names and passwords
 * @param width The width of the terminal
 * @param height The height of the terminal
 */
public SSHTerminal(SSHWindow sshWindow, ClientSession session, int width, int height) {
	super();
	this.sshWindow = sshWindow;
	this.session = session;
	TERM_WIDTH = width;
	TERM_HEIGHT = height;
	dumpContents = null;
	closeClient = false;
	isClosed = false;
	try {
		st = new SessionTerminal();
		forceUpdate = true;
		focus = false;
	} catch (IOException e) { e.printStackTrace(); }
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:24,代码来源:SSHTerminal.java


示例4: setUp

import org.apache.sshd.ClientSession; //导入依赖的package包/类
@SuppressWarnings("serial")
@Before
public void setUp() throws Exception {

	app = new Application() {
		@Override
		public void init() {}
	};
	mainWindow = new Window();
	app.setMainWindow(mainWindow);

	SSHWindow sshWindow = new SSHWindow(null, 200, 200);
	app.getMainWindow().addWindow(sshWindow);

	SshClient client = SshClient.setUpDefaultClient();
	client.start();
	ClientSession session = null;
	try {
		session = client.connect(testHost, testPort).await().getSession();
	} catch (Exception e) {
		fail("Could not connect to host");
	}
	sshTerm = new SSHTerminal(sshWindow, session, 200, 200);
	sshWindow.addComponent(sshTerm);
}
 
开发者ID:qoswork,项目名称:opennmszh,代码行数:26,代码来源:SSHTerminalTest.java


示例5: copyBootStrap

import org.apache.sshd.ClientSession; //导入依赖的package包/类
protected String copyBootStrap(ClientSession session) throws IOException {
    String dest = BOOTSTRAP_FILE.get() + random.nextLong();
    SftpClient sftpClient = session.createSftpClient();
    try {
        Handle handle = sftpClient.open(dest, EnumSet.of(OpenMode.Read, OpenMode.Write, OpenMode.Create, OpenMode.Exclusive));
        Attributes attr = new Attributes().perms(0700);
        sftpClient.setStat(handle, attr);
        byte[] content = getBootstrapSource(BOOTSTRAP_SOURCE_OVERRIDE.get(), BOOTSTRAP_SOURCE.get());
        sftpClient.write(handle, 0, content, 0, content.length);
        sftpClient.close(handle);

        return dest;
    } finally {
        if ( sftpClient != null ) {
            sftpClient.close();
        }
    }
}
 
开发者ID:ibuildthecloud,项目名称:dstack,代码行数:19,代码来源:SshAgentConnectionFactory.java


示例6: call

import org.apache.sshd.ClientSession; //导入依赖的package包/类
@Test(timeout = 10000L)
public void call() throws Exception {
    final SshClient client = SshClient.setUpDefaultClient();
    client.start();
    try {
        final ClientSession session = client.connect("localhost", 4222).await().getSession();
        session.authPassword("jonathan", "secret");

        final ClientChannel channel = session.createChannel("shell");
        ByteArrayOutputStream sent = new ByteArrayOutputStream();
        PipedOutputStream pipedIn = new TeePipedOutputStream(sent);
        channel.setIn(new PipedInputStream(pipedIn));
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        ByteArrayOutputStream err = new ByteArrayOutputStream();
        channel.setOut(out);
        channel.setErr(err);
        channel.open();

        pipedIn.write("properties\r\n".getBytes());
        pipedIn.flush();

        pipedIn.write("exit\r\n".getBytes());
        pipedIn.flush();

        channel.waitFor(ClientChannel.CLOSED, 0);
        channel.close(false);
        client.stop();

        assertTrue(new String(sent.toByteArray()).contains("properties\r\nexit\r\n"));
        assertTrue(new String(out.toByteArray()).contains("ServerService(id=ssh)"));
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
 
开发者ID:apache,项目名称:tomee,代码行数:36,代码来源:SSHServerTest.java


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


示例8: sendFile

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


示例9: authSuccess

import org.apache.sshd.ClientSession; //导入依赖的package包/类
protected boolean authSuccess(ClientSession session) {
    int ret = session.waitFor(ClientSession.CLOSED | ClientSession.AUTHED | ClientSession.WAIT_AUTH, SSH_TIMEOUT.get());

    if ((ret & ClientSession.AUTHED) != ClientSession.AUTHED) {
        return false;
    }

    return true;
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:10,代码来源:SshAgentConnectionFactory.java


示例10: SshAgentConnection

import org.apache.sshd.ClientSession; //导入依赖的package包/类
public SshAgentConnection(long agentId, String uri, EventService eventService, SshAgentConnectionFactory factory,
        ClientSession session, ChannelExec exec, int callbackPort) {
    super(agentId, uri, eventService);

    this.factory = factory;
    this.session = session;
    this.exec = exec;
    this.callbackPort = callbackPort;
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:10,代码来源:SshAgentConnection.java


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


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


示例13: setForwarding

import org.apache.sshd.ClientSession; //导入依赖的package包/类
protected int setForwarding(ClientSession session) throws IOException {
    SshdSocketAddress address = session.startRemotePortForwarding(new SshdSocketAddress("localhost", 0), new SshdSocketAddress("localhost", 8080));
    return address.getPort();
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:5,代码来源:SshAgentConnectionFactory.java


示例14: getSession

import org.apache.sshd.ClientSession; //导入依赖的package包/类
public ClientSession getSession() {
    return session;
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:4,代码来源:SshAgentConnection.java


示例15: setSession

import org.apache.sshd.ClientSession; //导入依赖的package包/类
public void setSession(ClientSession session) {
    this.session = session;
}
 
开发者ID:cloudnautique,项目名称:cloud-cattle,代码行数:4,代码来源:SshAgentConnection.java


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


示例17: getClientSession

import org.apache.sshd.ClientSession; //导入依赖的package包/类
public ClientSession getClientSession() {
	return session;
}
 
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:4,代码来源:ProxySession.java


示例18: setClientSession

import org.apache.sshd.ClientSession; //导入依赖的package包/类
public void setClientSession(ClientSession session) {
	this.session = session;
}
 
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:4,代码来源:ProxySession.java


示例19: SshConnection

import org.apache.sshd.ClientSession; //导入依赖的package包/类
public SshConnection(ClientSession session, ClientChannel channel)
		throws SshProxyJException {
	this.session = session;
	this.channel = channel;
}
 
开发者ID:northshorefiend,项目名称:sshproxyj,代码行数:6,代码来源:SshConnection.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ExtendedProducerProperties类代码示例发布时间:2022-05-22
下一篇:
Java InterpreterResult类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap