@Override public FileSystemConfigBuilder getConfigBuilder() { return FtpsFileSystemConfigBuilder.getInstance(); } }
/** * Gets the data channel protection level (PROT). * * @param opts The FileSystemOptions. * @return The PROT value. * @see org.apache.commons.net.ftp.FTPSClient#execPROT(String) * @since 2.1 */ public FtpsDataChannelProtectionLevel getDataChannelProtectionLevel(final FileSystemOptions opts) { return getEnum(FtpsDataChannelProtectionLevel.class, opts, PROT); }
/** * Gets the TrustManager that validates the FTPS server's certificate. * <p> * If the params do not contain the key for the trust manager, it will return a trust manger that simply checks this * certificate for validity. * </p> * * @param opts The FileSystemOptions. * @return the trust manager instance or {@code null} * @see org.apache.commons.net.ftp.FTPSClient#setTrustManager(TrustManager) * @since 2.1 */ public TrustManager getTrustManager(final FileSystemOptions opts) { final TrustManager trustManager; if (hasParam(opts, TRUST_MANAGER)) { trustManager = (TrustManager) getParam(opts, TRUST_MANAGER); } else { trustManager = TrustManagerUtils.getValidateServerCertificateTrustManager(); } return trustManager; }
FtpsFileSystemConfigBuilder configBuilder = FtpsFileSystemConfigBuilder.getInstance(); configBuilder.setPassiveMode(opts, Boolean.parseBoolean(passiveMode)); if (implicitMode != null) { if (Boolean.parseBoolean(implicitMode)) { configBuilder.setFtpsMode(opts, FtpsMode.IMPLICIT); } else { configBuilder.setFtpsMode(opts, FtpsMode.EXPLICIT); configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.P); } else if ("C".equalsIgnoreCase(protectionMode)) { configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.C); } else if ("S".equalsIgnoreCase(protectionMode)) { configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.S); } else if ("E".equalsIgnoreCase(protectionMode)) { configBuilder.setDataChannelProtectionLevel(opts, FtpsDataChannelProtectionLevel.E); configBuilder.setKeyStore(opts, keyStore); configBuilder.setTrustStore(opts, trustStore); configBuilder.setKeyStorePW(opts, keyStorePassword); configBuilder.setTrustStorePW(opts, trustStorePassword); configBuilder.setKeyPW(opts, keyPassword);
boolean shareSslContext = builder.getShareSslContext(fileSystemOptions); if (builder.getFtpsMode(fileSystemOptions) == FtpsMode.IMPLICIT) final TrustManager trustManager = builder.getTrustManager(fileSystemOptions); if (trustManager != null) final KeyManager keyManager = builder.getKeyManager(fileSystemOptions); if (keyManager != null) SocketFactoryWrapper socketFactoryWrapper = builder.getSocketFactoryWrapper(fileSystemOptions); if (socketFactoryWrapper != null) ServerSocketFactoryWrapper serverSocketFactoryWrapper = builder.getServerSocketFactoryWrapper(fileSystemOptions); if (serverSocketFactoryWrapper != null)
/** * Set FTPS type, either "implicit" or "explicit". * <p> * Note, that implicit mode is not standardized and considered as deprecated. Some unit tests for VFS fail with * implicit mode and it is not yet clear if its a problem with Commons VFS/Commons Net or our test server Apache * FTP/SSHD. * </p> * * @param opts The FileSystemOptions. * @param ftpsType The file type. * @see <a href="http://en.wikipedia.org/wiki/FTPS#Implicit">Wikipedia: FTPS/Implicit</a> * @deprecated As of 2.1, use {@link #setFtpsMode(FileSystemOptions, FtpsMode)} */ @Deprecated public void setFtpsType(final FileSystemOptions opts, final String ftpsType) { final FtpsMode mode; if (ftpsType != null) { mode = FtpsMode.valueOf(ftpsType.toUpperCase()); if (mode == null) { throw new IllegalArgumentException("Not a proper FTPS mode: " + ftpsType); } } else { mode = null; } setFtpsMode(opts, mode); }
@Override protected void setupOptions(final FtpsFileSystemConfigBuilder builder) { super.setupOptions(builder); builder.setDataChannelProtectionLevel(fileSystemOptions, FtpsDataChannelProtectionLevel.P); builder.setFtpsMode(fileSystemOptions, FtpsMode.EXPLICIT); }
@Override protected FTPSClient createClient(final FileSystemOptions fileSystemOptions) throws FileSystemException { final FTPSClient client; if (builder.getFtpsMode(fileSystemOptions) == FtpsMode.IMPLICIT) { client = new FTPSClient(true); } else { client = new FTPSClient(); } final TrustManager trustManager = builder.getTrustManager(fileSystemOptions); if (trustManager != null) { client.setTrustManager(trustManager); } final KeyManager keyManager = builder.getKeyManager(fileSystemOptions); if (keyManager != null) { client.setKeyManager(keyManager); } return client; }
FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); } else { setPassiveMode = setPassiveMode.trim(); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, Boolean.valueOf(setPassiveMode)); FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, Boolean.valueOf(setPassiveMode)); } catch (Exception e) {
@Override protected void setupOptions(final FtpsFileSystemConfigBuilder builder) { super.setupOptions(builder); builder.setDataChannelProtectionLevel(fileSystemOptions, FtpsDataChannelProtectionLevel.P); builder.setFtpsMode(fileSystemOptions, FtpsMode.EXPLICIT); builder.setShareSslContext(fileSystemOptions, true); }
@Override protected void setupOptions(final FtpsFileSystemConfigBuilder builder) { super.setupOptions(builder); builder.setFtpsMode(fileSystemOptions, FtpsMode.IMPLICIT); builder.setShareSslContext(fileSystemOptions, true); }
/** * Gets the KeyManager used to provide a client-side certificate if the FTPS server requests it. * * @param opts The FileSystemOptions. * @return the key manager instance or {@code null} * @see org.apache.commons.net.ftp.FTPSClient#setKeyManager(KeyManager) * @since 2.1 */ public KeyManager getKeyManager(final FileSystemOptions opts) { return (KeyManager) getParam(opts, KEY_MANAGER); }
/** * Return the FTPS type. Defaults to "explicit" if not defined. * * @param opts The FileSystemOptions. * @return The file type. * @see #setFtpsType * @deprecated As of 2.1, use {@link #getFtpsMode(FileSystemOptions)} */ @Deprecated public String getFtpsType(final FileSystemOptions opts) { return getFtpsMode(opts).name().toLowerCase(); }
@Override protected void setupOpenConnection(final FTPSClient client, final FileSystemOptions fileSystemOptions) throws IOException { final FtpsDataChannelProtectionLevel level = builder.getDataChannelProtectionLevel(fileSystemOptions); if (level != null) { // '0' means streaming, that's what we do! try { client.execPBSZ(0); client.execPROT(level.name()); } catch (final SSLException e) { throw new FileSystemException("vfs.provider.ftps/data-channel.level", e, level.toString()); } } } }
/** * Set FTPS type, either "implicit" or "explicit". * <p> * Note, that implicit mode is not standardized and considered as deprecated. Some unit tests for VFS fail with * implicit mode and it is not yet clear if its a problem with Commons VFS/Commons Net or our test server Apache * FTP/SSHD. * </p> * * @param opts The FileSystemOptions. * @param ftpsType The file type. * @see <a href="http://en.wikipedia.org/wiki/FTPS#Implicit">Wikipedia: FTPS/Implicit</a> * @deprecated As of 2.1, use {@link #setFtpsMode(FileSystemOptions, FtpsMode)} */ @Deprecated public void setFtpsType(final FileSystemOptions opts, final String ftpsType) { final FtpsMode mode; if (ftpsType != null) { mode = FtpsMode.valueOf(ftpsType.toUpperCase()); if (mode == null) { throw new IllegalArgumentException("Not a proper FTPS mode: " + ftpsType); } } else { mode = null; } setFtpsMode(opts, mode); }
@Override protected void setupOptions(final FtpsFileSystemConfigBuilder builder) { super.setupOptions(builder); builder.setDataChannelProtectionLevel(fileSystemOptions, FtpsDataChannelProtectionLevel.P); builder.setFtpsMode(fileSystemOptions, FtpsMode.EXPLICIT); }
@Override protected FTPSClient createClient(final FileSystemOptions fileSystemOptions) throws FileSystemException { final FTPSClient client; if (builder.getFtpsMode(fileSystemOptions) == FtpsMode.IMPLICIT) { client = new FTPSClient(true); } else { client = new FTPSClient(); } final TrustManager trustManager = builder.getTrustManager(fileSystemOptions); if (trustManager != null) { client.setTrustManager(trustManager); } final KeyManager keyManager = builder.getKeyManager(fileSystemOptions); if (keyManager != null) { client.setKeyManager(keyManager); } return client; }
/** * Get the default options for File system * * @return * @throws FileSystemException */ public static FileSystemOptions createDefaultOptions() throws FileSystemException { FileSystemOptions opts = new FileSystemOptions(); // SSH Key checking SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no"); // Root directory set to user home SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, false); // Timeout is count by Milliseconds SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 100000); FtpFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); FtpFileSystemConfigBuilder.getInstance().setSoTimeout(opts, 100000); FtpsFileSystemConfigBuilder.getInstance().setPassiveMode(opts, true); return opts; } }
/** * Gets the KeyManager used to provide a client-side certificate if the FTPS server requests it. * * @param opts The FileSystemOptions. * @return the key manager instance or {@code null} * @see org.apache.commons.net.ftp.FTPSClient#setKeyManager(KeyManager) * @since 2.1 */ public KeyManager getKeyManager(final FileSystemOptions opts) { return (KeyManager) getParam(opts, KEY_MANAGER); }
/** * Return the FTPS type. Defaults to "explicit" if not defined. * * @param opts The FileSystemOptions. * @return The file type. * @see #setFtpsType * @deprecated As of 2.1, use {@link #getFtpsMode(FileSystemOptions)} */ @Deprecated public String getFtpsType(final FileSystemOptions opts) { return getFtpsMode(opts).name().toLowerCase(); }