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

Java StreamGobbler类代码示例

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

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



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

示例1: getLogContent

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
@Override
public String getLogContent(String filename) throws RemoteException {
	StringBuilder sb=new StringBuilder();
	try {
		Session session=this.conn.openSession();
		session.execCommand("cat "+this.home+"/logs/"+filename);
		InputStream stdout=new StreamGobbler(session.getStdout());
		BufferedReader br=new BufferedReader(new InputStreamReader(stdout));
		String line=null;
		while((line=br.readLine())!=null){
			sb.append(line);
			sb.append("\n");
		}
		br.close();
		session.close();
	} catch (IOException e) {
		throw new RemoteException(e);
	}
	return sb.toString();
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:21,代码来源:RecLogger.java


示例2: connect

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public void connect(String userName, String password) throws Exception {
    this.connection = new Connection(ip);
    this.connection.connect();
    log.info("connected: " + ip + ":22");

    boolean isAuthenticated = connection.authenticateWithPassword(userName, password);
    if (isAuthenticated == false) {
        throw new IOException("Authentication failed.");
    }
    this.session = this.connection.openSession();
    this.session.startSubSystem("xmlagent");
    BufferedReader _reader = new BufferedReader(new InputStreamReader(this.session.getStdout()));
    this.reader = new WrapperReader(_reader);
    this.stdin = this.session.getStdin();
    this.writer = new BufferedWriter(new OutputStreamWriter(this.stdin));
    new StreamGobbler(this.session.getStderr());
    log.info("login: " + ip + ":22");
    log.info("server-hello: " + reader.readAll());
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:20,代码来源:NexusTest.java


示例3: setup

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
private void setup() throws IOException {
    String userName = this.node.getUserAccount();
    String password = this.node.getUserPassword();
    ProtocolPort pp = this.node.getProtocolPort(Protocol.SSH2);
    int port;
    if (pp == null) {
        port = 22;
    } else {
        port = pp.getPort();
    }
    log.info("connecting: " + ipAddress + ":" + port);
    this.connection = new Connection(ipAddress, port);
    this.connection.connect();
    log.info("connected: " + ipAddress + ":" + port);

    boolean isAuthenticated = connection.authenticateWithPassword(userName, password);
    if (isAuthenticated == false) {
        throw new IOException("Authentication failed.");
    }
    this.session = this.connection.openSession();
    this.session.startSubSystem("xmlagent");
    BufferedReader _reader = new BufferedReader(new InputStreamReader(this.session.getStdout()));
    this.reader = new WrapperReader(_reader);
    this.stdin = this.session.getStdin();
    this.writer = new BufferedWriter(new OutputStreamWriter(this.stdin));
    new StreamGobbler(this.session.getStderr());
    log.info("login: " + ipAddress + ":" + port);
    log.info("server-hello: " + reader.readAll());
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:30,代码来源:CiscoNexusNetConfClient.java


示例4: open

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public void open(IStreamLogger streamLogger) throws AuthenticationException {
  SshLogger.debug("opening session");
  mySession = mySessionProvider.compute();
  // wrapper created, inspection is inapplicable
  //noinspection IOResourceOpenedButNotSafelyClosed
  myInputStream = new MyInputStreamWrapper(myActivityMonitor, mySession.getStdout());
  // wrapper created, inspection is inapplicable
  //noinspection IOResourceOpenedButNotSafelyClosed
  myOutputStream = new MyOutputStreamWrapper(myActivityMonitor, mySession.getStdin());
  myErrorStreamGobbler = new StreamGobbler(mySession.getStderr());
  myState = LifeStages.CREATED;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:13,代码来源:SshSessionConnection.java


示例5: open

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public void open(IStreamLogger streamLogger) throws AuthenticationException {
  try {
    myConnection = SshConnectionUtils.openConnection(myConnectionSettings, myAuthentication);
    mySession = myConnection.openSession();
    mySession.execCommand("cvs server");
    new StreamGobbler(mySession.getStderr());
  }
  catch (IOException e) {
    throw new AuthenticationException(e.getMessage(), e);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:EmptyPool.java


示例6: communicate

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public static CommunicateResult communicate(Connection connection, Duration timeout, String... command) throws IOException {
    checkNotNull(connection);
    checkNotNull(timeout);
    checkNotNull(command);

    String commandString = quoteCommand(asList(command));
    Session session = connection.openSession();

    try {
        session.execCommand(commandString);

        StreamGobbler stderr = new StreamGobbler(session.getStderr());
        StreamGobbler stdout = new StreamGobbler(session.getStdout());

        try {
            session.waitForCondition(ChannelCondition.EXIT_STATUS, timeout.getMillis());
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
        }

        return new CommunicateResult(
                commandString,
                readAll(stdout, Charsets.UTF_8),
                readAll(stderr, Charsets.UTF_8),
                firstNonNull(session.getExitStatus(), -1000)
        );
    } finally {
        session.close();
    }
}
 
开发者ID:dump247,项目名称:jenkins-docker-build-plugin,代码行数:31,代码来源:Ssh.java


示例7: getLogFileNames

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
@Override
public List<LogProfile> getLogFileNames() throws RemoteException {
	List<LogProfile> logs=new LinkedList<LogProfile>();
	try {
		Session session=this.conn.openSession();
		String cmd="ls -l "+this.home+"/logs";
		session.execCommand(cmd);
		InputStream stdout=new StreamGobbler(session.getStdout());
		BufferedReader br=new BufferedReader(new InputStreamReader(stdout));
		String line=br.readLine();
		while(true){
			line=br.readLine();
			if(line==null){
				break;
			}
			String[] attrs=line.split("[ ]+");
			if(!attrs[7].endsWith(".log")){
				continue;
			}
			LogProfile log=new LogProfile();
			log.setName(attrs[7]);
			log.setOwner(attrs[2]);
			log.setGroup(attrs[3]);
			log.setSize(Long.parseLong(attrs[4]));
			logs.add(log);
		}
		br.close();
		session.close();
	} catch (IOException e) {
		throw new RemoteException(e);
	}
	return logs;
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:34,代码来源:RecLogger.java


示例8: execCommand

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
/**
 * Log in the remote host by ssh2 and execute the specified command.
 * 
 * @param cmd
 *            the command will be executed list the result information
 *            printed in the terminal after executing the "cmd" if there
 *            are. errorList the error information printed in the terminal
 *            after executing the "cmd" if there are.
 * @throws RemoteException 
 * 
 * */
public void execCommand(Connection conn, String cmd,
		ArrayList<String> list, ArrayList<String> errorList) throws RemoteException {

	try {
		/* Create a session */
		Session sess = conn.openSession();
		sess.execCommand(cmd);

		/*
		 * get the printed information of stdout and stderr.
		 */
		InputStream stdout = new StreamGobbler(sess.getStdout());
		br = new BufferedReader(new InputStreamReader(stdout));
		InputStream stderr = new StreamGobbler(sess.getStderr());
		errorbr = new BufferedReader(new InputStreamReader(stderr));

		while (true) {
			line = br.readLine();
			if (line == null)
				break;
			list.add(line);
		}

		while (true) {
			errorline = errorbr.readLine();
			if (errorline == null)
				break;
			errorList.add(errorline);
		}

		/* Close this session */
		sess.close();

	} catch (IOException e) {
		throw new RemoteException(e.getMessage());
		
	}
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:50,代码来源:RecAuthInfo.java


示例9: connect

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public void connect(final String username, final String password) throws IOException {
    if (getIpAddress() == null) {
        throw new IllegalStateException("ipAddress is null");
    }
    this.connection = new Connection(getIpAddress(), getPort());
    this.connection.connect();
    log.info("connected: " + getIpAddress() + ":" + getPort());

    boolean isAuthenticated = false;
    switch (this.method) {
        case SSH2:
            isAuthenticated = connection.authenticateWithPassword(username, password);
            break;
        case SSH2_INTERACTIVE:
            InteractiveCallback cb = new SimpleInteractiveCallback(password);
            isAuthenticated = connection.authenticateWithKeyboardInteractive(username, cb);
            break;
        case SSH2_PUBLICKEY:
        default:
            throw new IllegalStateException("unsupported method: " + this.method.name());
    }
    if (isAuthenticated == false) {
        throw new IOException("Authentication failed.");
    }
    this.session = this.connection.openSession();

    if (isVt100()) {
        this.session.requestPTY("vt100");
    } else {
        this.session.requestDumbPTY();
    }

    this.session.startShell();

    this.input = new PushbackInputStream(new StreamGobbler(this.session.getStdout()));
    this.output = this.session.getStdin();

    new StreamGobbler(this.session.getStderr());

    log.info("login: " + getIpAddress() + ":" + getPort());
}
 
开发者ID:openNaEF,项目名称:openNaEF,代码行数:42,代码来源:RealSsh2Socket.java


示例10: main

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public static void main(String[] args)
{
	String hostname = "127.0.0.1";
	String username = "joe";
	String password = "joespass";

	try
	{
		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* Now connect */

		conn.connect();

		/* Authenticate.
		 * If you get an IOException saying something like
		 * "Authentication method password not supported by the server at this stage."
		 * then please check the FAQ.
		 */

		boolean isAuthenticated = conn.authenticateWithPassword(username, password);

		if (isAuthenticated == false)
			throw new IOException("Authentication failed.");

		/* Create a session */

		Session sess = conn.openSession();

		sess.execCommand("uname -a && date && uptime && who");

		System.out.println("Here is some information about the remote host:");

		/* 
		 * This basic example does not handle stderr, which is sometimes dangerous
		 * (please read the FAQ).
		 */

		InputStream stdout = new StreamGobbler(sess.getStdout());

		BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

		while (true)
		{
			String line = br.readLine();
			if (line == null)
				break;
			System.out.println(line);
		}

		/* Show exit status, if available (otherwise "null") */

		System.out.println("ExitCode: " + sess.getExitStatus());

		/* Close this session */

		sess.close();

		/* Close the connection */

		conn.close();

	}
	catch (IOException e)
	{
		e.printStackTrace(System.err);
		System.exit(2);
	}
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:72,代码来源:Basic.java


示例11: main

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public static void main(String[] args)
{
	String hostname = "my-ssh-server";
	String username = "joe";
	String password = "joespass";

	String proxyHost = "192.168.1.1";
	int proxyPort = 3128; // default port used by squid
	
	try
	{
		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* We want to connect through a HTTP proxy */
		
		conn.setProxyData(new HTTPProxyData(proxyHost, proxyPort));
		
		// if the proxy requires basic authentication:
		// conn.setProxyData(new HTTPProxyData(proxyHost, proxyPort, "username", "secret"));
		
		/* Now connect (through the proxy) */

		conn.connect();

		/* Authenticate.
		 * If you get an IOException saying something like
		 * "Authentication method password not supported by the server at this stage."
		 * then please check the FAQ.
		 */

		boolean isAuthenticated = conn.authenticateWithPassword(username, password);

		if (isAuthenticated == false)
			throw new IOException("Authentication failed.");

		/* Create a session */

		Session sess = conn.openSession();

		sess.execCommand("uname -a && date && uptime && who");

		System.out.println("Here is some information about the remote host:");

		/* 
		 * This basic example does not handle stderr, which is sometimes dangerous
		 * (please read the FAQ).
		 */

		InputStream stdout = new StreamGobbler(sess.getStdout());

		BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

		while (true)
		{
			String line = br.readLine();
			if (line == null)
				break;
			System.out.println(line);
		}

		/* Show exit status, if available (otherwise "null") */

		System.out.println("ExitCode: " + sess.getExitStatus());

		/* Close this session */

		sess.close();

		/* Close the connection */

		conn.close();

	}
	catch (IOException e)
	{
		e.printStackTrace(System.err);
		System.exit(2);
	}
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:82,代码来源:BasicWithHTTPProxy.java


示例12: main

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public static void main(String[] args)
{
	String hostname = "127.0.0.1";
	String username = "joe";

	File keyfile = new File("~/.ssh/id_rsa"); // or "~/.ssh/id_dsa"
	String keyfilePass = "joespass"; // will be ignored if not needed

	try
	{
		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* Now connect */

		conn.connect();

		/* Authenticate */

		boolean isAuthenticated = conn.authenticateWithPublicKey(username, keyfile, keyfilePass);

		if (isAuthenticated == false)
			throw new IOException("Authentication failed.");

		/* Create a session */

		Session sess = conn.openSession();

		sess.execCommand("uname -a && date && uptime && who");

		InputStream stdout = new StreamGobbler(sess.getStdout());

		BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

		System.out.println("Here is some information about the remote host:");

		while (true)
		{
			String line = br.readLine();
			if (line == null)
				break;
			System.out.println(line);
		}

		/* Close this session */

		sess.close();

		/* Close the connection */

		conn.close();

	}
	catch (IOException e)
	{
		e.printStackTrace(System.err);
		System.exit(2);
	}
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:61,代码来源:PublicKeyAuthentication.java


示例13: main

import com.trilead.ssh2.StreamGobbler; //导入依赖的package包/类
public static void main(String[] args) throws IOException
{
	String hostname = "somehost";
	String username = "joe";
	String password = "joespass";

	File knownHosts = new File("~/.ssh/known_hosts");

	try
	{
		/* Load known_hosts file into in-memory database */

		if (knownHosts.exists())
			database.addHostkeys(knownHosts);

		/* Create a connection instance */

		Connection conn = new Connection(hostname);

		/* Now connect and use the SimpleVerifier */

		conn.connect(new SimpleVerifier(database));

		/* Authenticate */

		boolean isAuthenticated = conn.authenticateWithPassword(username, password);

		if (isAuthenticated == false)
			throw new IOException("Authentication failed.");

		/* Create a session */

		Session sess = conn.openSession();

		sess.execCommand("uname -a && date && uptime && who");

		InputStream stdout = new StreamGobbler(sess.getStdout());
		BufferedReader br = new BufferedReader(new InputStreamReader(stdout));

		System.out.println("Here is some information about the remote host:");

		while (true)
		{
			String line = br.readLine();
			if (line == null)
				break;
			System.out.println(line);
		}

		/* Close this session */

		sess.close();

		/* Close the connection */

		conn.close();

	}
	catch (IOException e)
	{
		e.printStackTrace(System.err);
		System.exit(2);
	}
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:65,代码来源:UsingKnownHosts.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java LinearComponentExtracter类代码示例发布时间:2022-05-22
下一篇:
Java JsonHelper类代码示例发布时间: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