本文整理汇总了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());
}
示例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>();
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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;
}
示例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)
);
}
示例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);
}
示例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;
}
示例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");
}
示例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;
}
示例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;
}
示例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());
}
示例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();
}