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


Java Connection类代码示例

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


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

示例1: connect

import com.trilead.ssh2.Connection; //导入依赖的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

示例2: SshSharedConnection

import com.trilead.ssh2.Connection; //导入依赖的package包/类
public SshSharedConnection(final String repository, final ConnectionSettings connectionSettings, final SshAuthentication authentication) {
  myValid = new AtomicBoolean(true);
  myRepository = repository;
  myConnectionSettings = connectionSettings;
  myLock = new Object();

  myConnectionFactory = new ThrowableComputable<Connection, AuthenticationException>() {
    public Connection compute() throws AuthenticationException {
      try {
        SshLogger.debug("connection factory called");
        return SshConnectionUtils.openConnection(connectionSettings, authentication);
      }
      catch (AuthenticationException e) {
        // todo +-
        myValid.set(false);
        throw e;
      } catch (IOException e) {
        // todo +-
        myValid.set(false);
        throw new AuthenticationException(e.getMessage(), e);
      }
    }
  };
  myQueue = new LinkedList<Cell>();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:SshSharedConnection.java

示例3: bySshWithEveryRetryWaitFor

import com.trilead.ssh2.Connection; //导入依赖的package包/类
/**
 * Connects to sshd on host:port
 * Retries while attempts reached with delay
 * First with tcp port wait, then with ssh connection wait
 *
 * @throws IOException if no retries left
 */
public void bySshWithEveryRetryWaitFor(int time, TimeUnit units) throws IOException {
    checkState(withEveryRetryWaitFor(time, units), "Port %s is not opened to connect to", hostAndPort.getPort());

    for (int i = 1; i <= retries; i++) {
        Connection connection = new Connection(hostAndPort.getHostText(), hostAndPort.getPort());
        try {
            connection.connect(null, 0, sshTimeoutMillis, sshTimeoutMillis);
            LOG.info("SSH port is open on {}:{}", hostAndPort.getHostText(), hostAndPort.getPort());
            return;
        } catch (IOException e) {
            LOG.error("Failed to connect to {}:{} (try {}/{}) - {}",
                    hostAndPort.getHostText(), hostAndPort.getPort(), i, retries, e.getMessage());
            if (i == retries) {
                throw e;
            }
        } finally {
            connection.close();
        }
        sleepFor(time, units);
    }
}
 
开发者ID:KostyaSha,项目名称:yet-another-docker-plugin,代码行数:29,代码来源:HostAndPortChecker.java

示例4: openTunnel

import com.trilead.ssh2.Connection; //导入依赖的package包/类
/***************************************************************************
 * Open the SSH tunnel
 **************************************************************************/
public void openTunnel() throws IOException
{
	if (m_connected)
	{
		Logger.debug("Closing previous session", Level.COMM, this);
		closeTunnel();
	}
	Logger.debug("Creating SSH connection", Level.COMM, this);
	m_connection = new Connection(m_serverInfo.getHost());
	Logger.debug("Opening SSH session", Level.COMM, this);
	m_connection.connect();
	Logger.debug("Authenticating", Level.COMM, this);
	Authenticator.authenticate(m_connection, m_serverInfo.getAuthentication());
	Logger.debug("Creating port forwarder", Level.COMM, this);
	m_localPort = findFreePort(m_localPort + 1);
	Logger.debug("localhost:" + m_localPort + " -> " + m_serverInfo.getHost() + ":" + m_serverInfo.getPort(), Level.COMM, this);
	m_fwd = m_connection.createLocalPortForwarder(m_localPort, "localhost", m_serverInfo.getPort());
	m_serverInfo.setPort(m_localPort);
	m_connected = true;
	Logger.debug("Tunnel connected", Level.COMM, this);
}
 
开发者ID:Spacecraft-Code,项目名称:SPELL,代码行数:25,代码来源:Tunneler.java

示例5: getConnection

import com.trilead.ssh2.Connection; //导入依赖的package包/类
private Connection getConnection(String servername,int serverport,
		String proxyhost,int proxyport,String proxyusername,String proxypassword)
{
	/* Create a connection instance */

	Connection conn = new Connection(servername,serverport);

	/* We want to connect through a HTTP proxy */
	if(usehttpproxy)
	{
		conn.setProxyData(new HTTPProxyData(proxyhost, proxyport));
	
		/* Now connect */
		// if the proxy requires basic authentication:
		if(useBasicAuthentication)
		{
			conn.setProxyData(new HTTPProxyData(proxyhost, proxyport, proxyusername, proxypassword));
		}
	}
	
	return conn;
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:23,代码来源:JobEntrySSH2GET.java

示例6: getConnection

import com.trilead.ssh2.Connection; //导入依赖的package包/类
private Connection getConnection(String servername,int serverpassword,
		String proxyhost,int proxyport,String proxyusername,String proxypassword)
{
	/* Create a connection instance */

	Connection connnect = new Connection(servername,serverpassword);

	/* We want to connect through a HTTP proxy */
	if(usehttpproxy)
	{
		connnect.setProxyData(new HTTPProxyData(proxyhost, proxyport));
	
		/* Now connect */
		// if the proxy requires basic authentication:
		if(useBasicAuthentication)
		{
			connnect.setProxyData(new HTTPProxyData(proxyhost, proxyport, proxyusername, proxypassword));
		}
	}
	
	return connnect;
}
 
开发者ID:icholy,项目名称:geokettle-2.0,代码行数:23,代码来源:JobEntrySSH2PUT.java

示例7: getConnection

import com.trilead.ssh2.Connection; //导入依赖的package包/类
private Connection getConnection(String servername,int serverport,
		String proxyhost,int proxyport,String proxyusername,String proxypassword)
{
	/* Create a connection instance */

	Connection connect = new Connection(servername,serverport);

	/* We want to connect through a HTTP proxy */
	if(usehttpproxy)
	{
		connect.setProxyData(new HTTPProxyData(proxyhost, proxyport));
	
		/* Now connect */
		// if the proxy requires basic authentication:
		if(useBasicAuthentication)
		{
			connect.setProxyData(new HTTPProxyData(proxyhost, proxyport, proxyusername, proxypassword));
		}
	}
	
	return connect;
}
 
开发者ID:yintaoxue,项目名称:read-open-source-code,代码行数:23,代码来源:JobEntrySSH2PUT.java

示例8: doFillCredentialsIdItems

import com.trilead.ssh2.Connection; //导入依赖的package包/类
public static ListBoxModel doFillCredentialsIdItems(@AncestorInPath ItemGroup context) {

            AccessControlled ac = (context instanceof AccessControlled ? (AccessControlled) context : Jenkins.getInstance());
            if (!ac.hasPermission(Jenkins.ADMINISTER)) {
                return new ListBoxModel();
            }

            return new SSHUserListBoxModel().withMatching(
                    SSHAuthenticator.matcher(Connection.class),
                    CredentialsProvider.lookupCredentials(
                            StandardUsernameCredentials.class,
                            context,
                            ACL.SYSTEM,
                            SSHLauncher.SSH_SCHEME)
            );
        }
 
开发者ID:jenkinsci,项目名称:docker-plugin,代码行数:17,代码来源:DockerTemplateBase.java

示例9: testRecRemoteOperatorAuthInfoString

import com.trilead.ssh2.Connection; //导入依赖的package包/类
@Test
public final void testRecRemoteOperatorAuthInfoString() throws IOException, RemoteException {
	String midwarePath = "/root/nginx/";
	AuthInfo authInfo= new RecAuthInfo();
	authInfo.setHost("10.1.50.4");
	authInfo.setUsername("root");
	authInfo.setPassword("cs2csolutions");


	Connection conn = new Connection("10.1.50.4");
	/* Now connect */
	conn.connect();
	boolean isAuthenticated = conn.authenticateWithPassword(
			"root", "cs2csolutions");
	if (isAuthenticated == false)
		throw new RemoteException("Authentication failed.");
	
	RecRemoteOperator rro1 = new RecRemoteOperator(authInfo,midwarePath,conn);

	assertTrue(null != rro1);
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:22,代码来源:RecRemoteOperatorTest.java

示例10: scopy

import com.trilead.ssh2.Connection; //导入依赖的package包/类
/**
 * Copy the local file named zipFile to remote host and the the target
 * location is targetPath.
 * 
 * @param zipFile
 *            local zipFile
 * @param targetPath
 *            target location in the remote host
 * @throws RemoteException
 *             When this remote operation fails for any non-local reason.
 * @throws IOException
 *             When connect remote host by ssh2
 * */
public boolean scopy(Connection conn, File zipFile, String targetPath)
		throws IOException, RemoteException {
	String zipFileName = zipFile.toString();
	targetPath = pathStrConvert(targetPath);

	try
	{
		SCPClient scpc = conn.createSCPClient();
		mkdirTargetPath(targetPath);
		scpc.put(zipFileName, targetPath);
	
	}catch(IllegalStateException e)
	{
		throw new RemoteException(e.getMessage());
	}
	//System.out.println(zipFileName+"   "+targetPath);
	//mkdir targetPath
	
	if (isExistedFile(targetPath, zipFile.getName()) == false)
		throw new RemoteException("File scp failed");

	return true;
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:37,代码来源:RecController.java

示例11: setUpBeforeClass

import com.trilead.ssh2.Connection; //导入依赖的package包/类
/**
 * @throws java.lang.Exception
 */
@BeforeClass
public static void setUpBeforeClass() throws Exception {
	/* Create a connection instance */
	conn = new Connection("10.1.50.4", 22);
	
	/* Connect */
	conn.connect();

	/* Authenticate. */
	boolean isAuthenticated = 
	conn.authenticateWithPassword("root", "cs2csolutions");
	if (isAuthenticated == false)
		throw new IOException("Authentication failed.");
	logger=new RecLogger(conn, "/usr/local/nginx");
}
 
开发者ID:MToLinux,项目名称:Nginxlib,代码行数:19,代码来源:LoggerTest.java

示例12: getConnection

import com.trilead.ssh2.Connection; //导入依赖的package包/类
private Connection getConnection( String servername, int serverport, String proxyhost, int proxyport,
  String proxyusername, String proxypassword ) {
  /* Create a connection instance */

  Connection conn = new Connection( servername, serverport );

  /* We want to connect through a HTTP proxy */
  if ( usehttpproxy ) {
    conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) );

    /* Now connect */
    // if the proxy requires basic authentication:
    if ( useBasicAuthentication ) {
      conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) );
    }
  }

  return conn;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:20,代码来源:JobEntrySSH2GET.java

示例13: getConnection

import com.trilead.ssh2.Connection; //导入依赖的package包/类
private Connection getConnection( String servername, int serverport, String proxyhost, int proxyport,
  String proxyusername, String proxypassword ) {
  /* Create a connection instance */

  Connection connect = new Connection( servername, serverport );

  /* We want to connect through a HTTP proxy */
  if ( usehttpproxy ) {
    connect.setProxyData( new HTTPProxyData( proxyhost, proxyport ) );

    /* Now connect */
    // if the proxy requires basic authentication:
    if ( useBasicAuthentication ) {
      connect.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) );
    }
  }

  return connect;
}
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:20,代码来源:JobEntrySSH2PUT.java

示例14: setup

import com.trilead.ssh2.Connection; //导入依赖的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

示例15: openConnectionSessionTest

import com.trilead.ssh2.Connection; //导入依赖的package包/类
@Test
public void openConnectionSessionTest() throws IOException, InterruptedException {
    final Connection conn = Mockito.mock(Connection.class);
    PowerMockito.mockStatic(Thread.class);
    SshHelper.openConnectionSession(conn);

    Mockito.verify(conn).openSession();

    PowerMockito.verifyStatic();
}
 
开发者ID:MissionCriticalCloud,项目名称:cosmic,代码行数:11,代码来源:SshHelperTest.java


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