/** * {@link org.apache.commons.vfs2.provider.sftp.SftpFileSystem#getChannel() } * */ private void ensureSession() throws FileSystemException { if ( this.session == null || !this.session.isConnected() ) { this.doCloseCommunicationLink(); UserAuthenticationData authData = null; Session session; try { GenericFileName e = (GenericFileName) this.getRootName(); authData = UserAuthenticatorUtils.authenticate( this.getFileSystemOptions(), SftpFileProvider.AUTHENTICATOR_TYPES ); session = SftpClientFactory.createConnection( e.getHostName(), e.getPort(), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar( e.getUserName() ) ), UserAuthenticatorUtils.getData( authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar( e.getPassword() ) ), this.getFileSystemOptions() ); } catch ( Exception var7 ) { throw new FileSystemException( "vfs.provider.sftp/connect.error", this.getRootName(), var7 ); } finally { UserAuthenticatorUtils.cleanup( authData ); } this.session = session; } }
private static void addIdentities(final JSch jsch, final File sshDir, final IdentityInfo[] identities) throws FileSystemException { if (identities != null) { for (final IdentityInfo info : identities) { addIndentity(jsch, info); } } else { // Load the private key (rsa-key only) final File privateKeyFile = new File(sshDir, "id_rsa"); if (privateKeyFile.isFile() && privateKeyFile.canRead()) { addIndentity(jsch, new IdentityInfo(privateKeyFile)); } } }
final IdentityRepositoryFactory repositoryFactory = builder.getIdentityRepositoryFactory(fileSystemOptions); sshDir = findSshDir(); setKnownHosts(jsch, sshDir, knownHostsFile); addIdentities(jsch, sshDir, identities); Proxy proxy = null; if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) { proxy = createProxyHTTP(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) { proxy = createProxySOCKS5(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType)) { proxy = createStreamProxy(proxyHost, proxyPort, fileSystemOptions, builder);
final IdentityRepositoryFactory repositoryFactory = builder.getIdentityRepositoryFactory(fileSystemOptions); sshDir = findSshDir(); setKnownHosts(jsch, sshDir, knownHostsFile); addIdentities(jsch, sshDir, identities); Proxy proxy = null; if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) { proxy = createProxyHTTP(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) { proxy = createProxySOCKS5(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType)) { proxy = createStreamProxy(proxyHost, proxyPort, fileSystemOptions, builder);
final boolean loadOpenSSHConfig = builder.isLoadOpenSSHConfig(fileSystemOptions); sshDir = findSshDir(); setKnownHosts(jsch, sshDir, knownHostsFile); addIdentities(jsch, sshDir, identities); setConfigRepository(jsch, sshDir, configRepository, loadOpenSSHConfig); Proxy proxy = null; if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) { proxy = createProxyHTTP(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_SOCKS5.equals(proxyType)) { proxy = createProxySOCKS5(proxyHost, proxyPort); } else if (SftpFileSystemConfigBuilder.PROXY_STREAM.equals(proxyType)) { proxy = createStreamProxy(proxyHost, proxyPort, fileSystemOptions, builder);
@Override public void connect(final SocketFactory socketFactory, final String targetHost, final int targetPort, final int timeout) throws Exception { session = SftpClientFactory.createConnection(proxyHost, proxyPort, proxyUser.toCharArray(), proxyPassword.toCharArray(), proxyOptions); channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(String.format(commandFormat, targetHost, targetPort)); channel.connect(timeout); }
private static void addIdentities(final JSch jsch, final File sshDir, final IdentityInfo[] identities) throws FileSystemException { if (identities != null) { for (final IdentityInfo info : identities) { addIndentity(jsch, info); } } else { // Load the private key (rsa-key only) final File privateKeyFile = new File(sshDir, "id_rsa"); if (privateKeyFile.isFile() && privateKeyFile.canRead()) { addIndentity(jsch, new IdentityInfo(privateKeyFile)); } } }
final IdentityRepositoryFactory repositoryFactory = builder.getIdentityRepositoryFactory(fileSystemOptions); sshDir = findSshDir(); setKnownHosts(jsch, sshDir, knownHostsFile); addIdentities(jsch, sshDir, identities); if (SftpFileSystemConfigBuilder.PROXY_HTTP.equals(proxyType)) proxy = createProxyHTTP(proxyHost, proxyPort); proxy = createProxySOCKS5(proxyHost, proxyPort); proxy = createStreamProxy(proxyHost, proxyPort, fileSystemOptions, builder);
@Override public void connect(final SocketFactory socketFactory, final String targetHost, final int targetPort, final int timeout) throws Exception { session = SftpClientFactory.createConnection(proxyHost, proxyPort, proxyUser.toCharArray(), proxyPassword.toCharArray(), proxyOptions); channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(String.format(commandFormat, targetHost, targetPort)); channel.connect(timeout); }
private static void addIdentities(final JSch jsch, final File sshDir, final IdentityInfo[] identities) throws FileSystemException { if (identities != null) { for (final IdentityInfo info : identities) { addIndentity(jsch, info); } } else { // Load the private key (rsa-key only) final File privateKeyFile = new File(sshDir, "id_rsa"); if (privateKeyFile.isFile() && privateKeyFile.canRead()) { addIndentity(jsch, new IdentityInfo(privateKeyFile)); } } }
@Override public void connect(final SocketFactory socketFactory, final String targetHost, final int targetPort, final int timeout) throws Exception { session = SftpClientFactory.createConnection(proxyHost, proxyPort, proxyUser.toCharArray(), proxyPassword.toCharArray(), proxyOptions); channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(String.format(commandFormat, targetHost, targetPort)); channel.connect(timeout); }
public static void addIdentities(final JSch jsch, final File sshDir, final IdentityInfo[] identities) throws FileSystemException { if (identities != null) { for (final IdentityInfo info : identities) { addIndentity(jsch, info); } } else { // Load the private key (rsa-key only) final File privateKeyFile = new File(sshDir, "id_rsa"); if (privateKeyFile.isFile() && privateKeyFile.canRead()) { addIndentity(jsch, new IdentityInfo(privateKeyFile)); } } }
@Override public void connect(final SocketFactory socketFactory, final String targetHost, final int targetPort, final int timeout) throws Exception { session = SftpClientFactory.createConnection(proxyHost, proxyPort, proxyUser.toCharArray(), proxyPassword.toCharArray(), proxyOptions); channel = (ChannelExec) session.openChannel("exec"); channel.setCommand(String.format(commandFormat, targetHost, targetPort)); channel.connect(timeout); }
/** * 获取SFTP实例 * @param host 主机 * @param port 端口 * @param user 用户 * @param password 密码 * @return * @throws FileSystemException * @throws JSchException */ public static SFTPUtils getInstance(String host, int port, String user, String password) throws FileSystemException, JSchException { FileSystemOptions vfs = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(vfs, "no"); session = SftpClientFactory.createConnection(host, port, user.toCharArray(), password.toCharArray(), vfs); Channel channel = session.openChannel("sftp"); channel.connect(); cs = (ChannelSftp) channel; return new SFTPUtils(); }
try { session = SftpClientFactory.createConnection(ftpServer, port, username.toCharArray(), password.toCharArray(), fileSystemOptions);
session = SftpClientFactory.createConnection( rootName.getHostName(), rootName.getPort(),
/** * Creates a {@link FileSystem}. */ @Override protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) throws FileSystemException { // JSch jsch = createJSch(fileSystemOptions); // Create the file system final GenericFileName rootName = (GenericFileName) name; Session session; UserAuthenticationData authData = null; try { authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())), fileSystemOptions); } catch (final Exception e) { throw new FileSystemException("vfs.provider.sftp/connect.error", name, e); } finally { UserAuthenticatorUtils.cleanup(authData); } return new SftpFileSystem(rootName, session, fileSystemOptions); }
/** * Creates a {@link FileSystem}. */ @Override protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) throws FileSystemException { // JSch jsch = createJSch(fileSystemOptions); // Create the file system final GenericFileName rootName = (GenericFileName) name; Session session; UserAuthenticationData authData = null; try { authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())), fileSystemOptions); } catch (final Exception e) { throw new FileSystemException("vfs.provider.sftp/connect.error", name, e); } finally { UserAuthenticatorUtils.cleanup(authData); } return new SftpFileSystem(rootName, session, fileSystemOptions); }
/** * Creates a {@link FileSystem}. */ @Override protected FileSystem doCreateFileSystem(final FileName name, final FileSystemOptions fileSystemOptions) throws FileSystemException { // JSch jsch = createJSch(fileSystemOptions); // Create the file system final GenericFileName rootName = (GenericFileName) name; Session session; UserAuthenticationData authData = null; try { authData = UserAuthenticatorUtils.authenticate(fileSystemOptions, AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection(rootName.getHostName(), rootName.getPort(), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.USERNAME, UserAuthenticatorUtils.toChar(rootName.getUserName())), UserAuthenticatorUtils.getData(authData, UserAuthenticationData.PASSWORD, UserAuthenticatorUtils.toChar(rootName.getPassword())), fileSystemOptions); } catch (final Exception e) { throw new FileSystemException("vfs.provider.sftp/connect.error", name, e); } finally { UserAuthenticatorUtils.cleanup(authData); } return new SftpFileSystem(rootName, session, fileSystemOptions); }
SftpFileProvider.AUTHENTICATOR_TYPES); session = SftpClientFactory.createConnection( rootName.getHostName(), rootName.getPort(),