本文整理汇总了Java中com.trilead.ssh2.Connection.setProxyData方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.setProxyData方法的具体用法?Java Connection.setProxyData怎么用?Java Connection.setProxyData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.trilead.ssh2.Connection
的用法示例。
在下文中一共展示了Connection.setProxyData方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例4: 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;
}
示例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 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;
}
示例6: openConnection
import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public static Connection openConnection(final ConnectionSettings connectionSettings, final SshAuthentication authentication)
throws AuthenticationException, IOException {
final int port = connectionSettings.getPort() == -1 ? SSH_DEFAULT_PORT : connectionSettings.getPort();
final Connection connection = new Connection(connectionSettings.getHostName(), port);
final ProxyData proxy = SshProxyFactory.createAndRegister(connectionSettings);
if (proxy != null) {
connection.setProxyData(proxy);
}
connection.connect(null, connectionSettings.getConnectionTimeout(), connectionSettings.getConnectionTimeout());
authentication.authenticate(connection);
//HTTPProxyException
return connection;
}
示例7: main
import com.trilead.ssh2.Connection; //导入方法依赖的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);
}
}
示例8: SSHConnect
import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect(LogWriter log,String realservername, String realserverpassword, int realserverport,
String realUsername, String realPassword,
String realproxyhost,String realproxyusername, String realproxypassword, int realproxyport,
String realkeyFilename, String realkeyPass) throws Exception
{
/* Create a connection instance */
Connection conn = new Connection(realservername,realserverport);
/* We want to connect through a HTTP proxy */
if(useproxy)
{
conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport));
/* Now connect */
// if the proxy requires basic authentication:
if(!Const.isEmpty(realproxyusername) || !Const.isEmpty(realproxypassword))
{
conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport, realproxyusername, realproxypassword));
}
}
if(timeout>0)
{
// Use timeout
conn.connect(null,0,timeout*1000);
}else
{
// Cache Host Key
conn.connect();
}
// Authenticate
boolean isAuthenticated = false;
if(publicpublickey)
{
isAuthenticated=conn.authenticateWithPublicKey(realUsername, new File(keyFilename), realkeyPass);
}else
{
isAuthenticated=conn.authenticateWithPassword(realUsername, realserverpassword);
}
if(!isAuthenticated) throw new Exception("Can not connect to ");
sshclient = new SFTPv3Client(conn);
}
示例9: SSHConnect
import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect(String realservername, String realserverpassword, int realserverport,
String realUsername, String realPassword,
String realproxyhost,String realproxyusername, String realproxypassword, int realproxyport,
String realkeyFilename, String realkeyPass) throws Exception
{
/* Create a connection instance */
Connection conn = new Connection(realservername,realserverport);
/* We want to connect through a HTTP proxy */
if(useproxy)
{
conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport));
/* Now connect */
// if the proxy requires basic authentication:
if(!Const.isEmpty(realproxyusername) || !Const.isEmpty(realproxypassword))
{
conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport, realproxyusername, realproxypassword));
}
}
if(timeout>0)
{
// Use timeout
conn.connect(null,0,timeout*1000);
}else
{
// Cache Host Key
conn.connect();
}
// Authenticate
boolean isAuthenticated = false;
if(publicpublickey)
{
isAuthenticated=conn.authenticateWithPublicKey(realUsername, new File(keyFilename), realkeyPass);
}else
{
isAuthenticated=conn.authenticateWithPassword(realUsername, realserverpassword);
}
if(!isAuthenticated) throw new Exception("Can not connect to ");
sshclient = new SFTPv3Client(conn);
}
示例10: SSHConnect
import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect(String realservername, String realserverpassword, int realserverport,
String realUsername, String realPassword,
String realproxyhost,String realproxyusername, String realproxypassword, int realproxyport,
String realkeyFilename, String realkeyPass) throws Exception
{
/* Create a connection instance */
Connection conn = new Connection(realservername,realserverport);
/* We want to connect through a HTTP proxy */
if(useproxy)
{
conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport));
/* Now connect */
// if the proxy requires basic authentication:
if(!Const.isEmpty(realproxyusername) || !Const.isEmpty(realproxypassword))
{
conn.setProxyData(new HTTPProxyData(realproxyhost, realproxyport, realproxyusername, realproxypassword));
}
}
if(timeout>0)
{
// Use timeout
conn.connect(null,0,timeout*1000);
}else
{
// Cache Host Key
conn.connect();
}
// Authenticate
boolean isAuthenticated = false;
if(publicpublickey)
{
isAuthenticated=conn.authenticateWithPublicKey(realUsername, new File(realkeyFilename), realkeyPass);
}else
{
isAuthenticated=conn.authenticateWithPassword(realUsername, realserverpassword);
}
if(!isAuthenticated) throw new Exception("Can not connect to ");
sshclient = new SFTPv3Client(conn);
}
示例11: SSHConnect
import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
private void SSHConnect( String realservername, String realserverpassword, int realserverport,
String realUsername, String realPassword, String realproxyhost, String realproxyusername,
String realproxypassword, int realproxyport, String realkeyFilename, String realkeyPass ) throws Exception {
/* Create a connection instance */
Connection conn = new Connection( realservername, realserverport );
/* We want to connect through a HTTP proxy */
if ( useproxy ) {
conn.setProxyData( new HTTPProxyData( realproxyhost, realproxyport ) );
/* Now connect */
// if the proxy requires basic authentication:
if ( !Utils.isEmpty( realproxyusername ) || !Utils.isEmpty( realproxypassword ) ) {
conn
.setProxyData( new HTTPProxyData( realproxyhost, realproxyport, realproxyusername, realproxypassword ) );
}
}
if ( timeout > 0 ) {
// Use timeout
conn.connect( null, 0, timeout * 1000 );
} else {
// Cache Host Key
conn.connect();
}
// Authenticate
boolean isAuthenticated = false;
if ( publicpublickey ) {
isAuthenticated = conn.authenticateWithPublicKey( realUsername, new File( realkeyFilename ), realkeyPass );
} else {
isAuthenticated = conn.authenticateWithPassword( realUsername, realserverpassword );
}
if ( !isAuthenticated ) {
throw new Exception( "Can not connect to " );
}
sshclient = new SFTPv3Client( conn );
}
示例12: OpenConnection
import com.trilead.ssh2.Connection; //导入方法依赖的package包/类
public static Connection OpenConnection( String serveur, int port, String username, String password,
boolean useKey, String keyFilename, String passPhrase, int timeOut, VariableSpace space, String proxyhost,
int proxyport, String proxyusername, String proxypassword ) throws KettleException {
Connection conn = null;
char[] content = null;
boolean isAuthenticated = false;
try {
// perform some checks
if ( useKey ) {
if ( Utils.isEmpty( keyFilename ) ) {
throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyFileMissing" ) );
}
FileObject keyFileObject = KettleVFS.getFileObject( keyFilename );
if ( !keyFileObject.exists() ) {
throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.PrivateKeyNotExist", keyFilename ) );
}
FileContent keyFileContent = keyFileObject.getContent();
CharArrayWriter charArrayWriter = new CharArrayWriter( (int) keyFileContent.getSize() );
try ( InputStream in = keyFileContent.getInputStream() ) {
IOUtils.copy( in, charArrayWriter );
}
content = charArrayWriter.toCharArray();
}
// Create a new connection
conn = createConnection( serveur, port );
/* We want to connect through a HTTP proxy */
if ( !Utils.isEmpty( proxyhost ) ) {
/* Now connect */
// if the proxy requires basic authentication:
if ( !Utils.isEmpty( proxyusername ) ) {
conn.setProxyData( new HTTPProxyData( proxyhost, proxyport, proxyusername, proxypassword ) );
} else {
conn.setProxyData( new HTTPProxyData( proxyhost, proxyport ) );
}
}
// and connect
if ( timeOut == 0 ) {
conn.connect();
} else {
conn.connect( null, 0, timeOut * 1000 );
}
// authenticate
if ( useKey ) {
isAuthenticated =
conn.authenticateWithPublicKey( username, content, space.environmentSubstitute( passPhrase ) );
} else {
isAuthenticated = conn.authenticateWithPassword( username, password );
}
if ( isAuthenticated == false ) {
throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.AuthenticationFailed", username ) );
}
} catch ( Exception e ) {
// Something wrong happened
// do not forget to disconnect if connected
if ( conn != null ) {
conn.close();
}
throw new KettleException( BaseMessages.getString( SSHMeta.PKG, "SSH.Error.ErrorConnecting", serveur, username ), e );
}
return conn;
}