org.apache.commons.net.ftp.FTPSClient Java Examples
The following examples show how to use
org.apache.commons.net.ftp.FTPSClient.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FtpClient.java From netbeans with Apache License 2.0 | 6 votes |
private FTPClient createFtpClient(FtpConfiguration configuration) { FtpConfiguration.Security security = configuration.getSecurity(); if (!security.isPresent()) { LOGGER.log(Level.FINE, "No encryption used"); ProxyInfo proxyInfo = RemoteUtils.getHttpProxy(configuration.getHost()); if (proxyInfo != null) { LOGGER.log(Level.FINE, "HTTP proxy will be used"); return new FTPHTTPClient(proxyInfo.getHost(), proxyInfo.getPort(), proxyInfo.getUsername(), proxyInfo.getPassword()); } // no proxy LOGGER.log(Level.FINE, "No proxy will be used"); return new FTPClient(); } Encryption encryption = security.getEncryption(); LOGGER.log(Level.FINE, "Used encryption {0}", encryption.name()); // can be debugged by setting -J-Djavax.net.debug=all return new FTPSClient(encryption.getProtocol(), encryption.isImplicit()); }
Example #2
Source File: MultipleConnectionTestCase.java From commons-vfs with Apache License 2.0 | 6 votes |
@Test public void testUnderlyingConnect() throws SocketException, IOException { final FTPSClient client1 = this.init(new FTPSClient(true)); final FTPSClient client2 = this.init(new FTPSClient(true)); try { final String hostname = "localhost"; client1.connect(hostname, AbstractFtpsProviderTestCase.getSocketPort()); client2.connect(hostname, AbstractFtpsProviderTestCase.getSocketPort()); } finally { if (client1 != null) { client1.disconnect(); } if (client2 != null) { client2.disconnect(); } } }
Example #3
Source File: FTPDropbox2Publisher.java From datasync with MIT License | 5 votes |
/** * * Uploads the given input stream to the working directory of the given FTP object. * If transfer was successful (including no partial file transfers), move file to * the 'enqueue-job' directory. * * @param ftp authenticated ftps object * @param in input stream with contents to upload as a file * @param path absolute path on FTP server where file will be uploaded * @param filesize size (in bytes) the uploaded file should be (if filesize == 0, do * do not check filesize) * @return a string in the format of 'SUCCESS', if no errors or 'FAILURE: <error message>', * if there was an error during any step of the process */ private static String uploadAndEnqueue(FTPSClient ftp, InputStream in, final String path, long filesize) { try { if (!ftp.storeFile(path, in)) { return FAILURE_PREFIX + ": " + ftp.getReplyString(); } if(filesize != 0) { // verify the uploaded filesize == given filesize System.out.println("Verifying uploaded filesize of " + path + "..."); long uploadedFilesize = getFTPFilesize(ftp, path); if(filesize != uploadedFilesize) { return String.format(FAILURE_PREFIX + ": uploaded filesize (%d B) " + "did not match local filesize (%d B)", uploadedFilesize, filesize); } } // upload to enqueue directory File fileFromPath = new File(path); String datasetDirPath = fileFromPath.getParent(); System.out.println("Enqueing job - ftp.rename(" + path + ", " + datasetDirPath + "/" + FTP_ENQUEUE_JOB_DIRNAME + ")"); issueFtpCommandWithRetries(ftp, "rename", path, datasetDirPath + "/" + FTP_ENQUEUE_JOB_DIRNAME); } catch (IOException e) { e.printStackTrace(); return FAILURE_PREFIX + ": " + e.getMessage(); } return SUCCESS_PREFIX; }
Example #4
Source File: FTPDropbox2Publisher.java From datasync with MIT License | 5 votes |
/** * Records the DataSync version of this JAR/code (for tracking purposes). If setting the version * fails just print a message and do nothing else. * * @param ftp authenticated ftps object * @param pathToDataSyncVersionFile absolute path on FTP server where 'datasync-version' file is located */ private static void recordDataSyncVersion(FTPSClient ftp, String pathToDataSyncVersionFile) { try { String currentDataSyncVersion = VersionProvider.getThisVersion(); System.out.println("Recording DataSync version being used (" + currentDataSyncVersion + ")"); InputStream inputDataSyncVersion = new ByteArrayInputStream(currentDataSyncVersion.getBytes("UTF-8")); System.out.println("Setting job request ID - ftp.storeFile(" + pathToDataSyncVersionFile + ", " + inputDataSyncVersion + ")"); if (!ftp.storeFile(pathToDataSyncVersionFile, inputDataSyncVersion)) { System.out.println("Failed to record DataSync version: " + ftp.getReplyString() + " Continuing..."); } inputDataSyncVersion.close(); } catch (Exception e) { System.out.println("Failed to record DataSync version: " + e.getMessage() + ". Continuing..."); } }
Example #5
Source File: FTPDropbox2Publisher.java From datasync with MIT License | 5 votes |
/** * Sets (and returns) the FTP requestId to be a random 32 character hexidecimal value * * @param ftp authenticated ftps object * @param pathToRequestIdFile bsolute path on FTP server where requestId file is located * @return requestId that was set or if there was an error return error message in the * form 'FAILURE:...' * @throws java.io.IOException */ private static String setFTPRequestId(FTPSClient ftp, String pathToRequestIdFile) throws IOException { String requestId = Utils.generateRequestId(); InputStream inputRequestId = new ByteArrayInputStream(requestId.getBytes("UTF-8")); System.out.println("Setting job request ID - ftp.storeFile(" + pathToRequestIdFile + ", " + inputRequestId + ")"); if (!ftp.storeFile(pathToRequestIdFile, inputRequestId)) { return FAILURE_PREFIX + ": " + ftp.getReplyString(); } inputRequestId.close(); return requestId; }
Example #6
Source File: FTPDropbox2Publisher.java From datasync with MIT License | 5 votes |
/** * Determines path on FTP server to domain root * * @param ftp * @param connectionInfo * @return "" if user user, or "/<DOMAIN>/" if user is SuperAdmin or has multi-domain access * @throws java.io.IOException */ private static String getPathToDomainRoot(FTPSClient ftp, SocrataConnectionInfo connectionInfo) throws IOException { String pathToDomainRoot = ""; System.out.println("Obtaining login role - ftp.listFiles(" + FTP_REQUEST_ID_FILENAME + ")"); FTPFile[] checkRequestIdFile = ftp.listFiles(FTP_REQUEST_ID_FILENAME); if(checkRequestIdFile.length == 0) { // user is a SuperAdmin or has multi-domain access String domainWithoutHTTP = connectionInfo.getUrl().replaceAll("https://", ""); domainWithoutHTTP = domainWithoutHTTP.replaceAll("/", ""); pathToDomainRoot = "/" + domainWithoutHTTP; } return pathToDomainRoot; }
Example #7
Source File: FtpsClientFactory.java From commons-vfs with Apache License 2.0 | 5 votes |
@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()); } } }
Example #8
Source File: ConnectionStressTest.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void run() { try { FTPSClient c = new FTPSClient(); c.configure(ftpConfig); logger.debug("Trying to connect"); c.connect("127.0.0.1", 2121); logger.debug("Connected"); c.setSoTimeout(5000); if (!FTPReply.isPositiveCompletion(c.getReplyCode())) { logger.debug("Houston, we have a problem. D/C"); c.disconnect(); throw new Exception(); } if (c.login("drftpd", "drftpd")) { logger.debug("Logged-in, now waiting 5 secs and kill the thread."); _sc.addSuccess(); Thread.sleep(5000); c.disconnect(); } else { logger.debug("Login failed, D/C!"); throw new Exception(); } } catch (Exception e) { logger.debug(e, e); _sc.addFailure(); } logger.debug("exiting"); }
Example #9
Source File: FTPUtils.java From TranskribusCore with GNU General Public License v3.0 | 5 votes |
public static void connectToFTP(FTPSClient ftp, String ftpServer, int ftpPort) throws SocketException, IOException { ftp.connect(ftpServer, ftpPort); // After connection attempt, you should check the reply code to verify // success. int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); throw new IOException("FTP server refused connection, reply code: " + reply); } logger.debug("Connected to " + ftpServer + "."+ftp.getReplyString()); }
Example #10
Source File: ConnectionStressTest.java From drftpd with GNU General Public License v2.0 | 5 votes |
public void run() { try { FTPSClient c = new FTPSClient(); c.configure(ftpConfig); logger.debug("Trying to connect"); c.connect("127.0.0.1", 2121); logger.debug("Connected"); c.setSoTimeout(5000); if (!FTPReply.isPositiveCompletion(c.getReplyCode())) { logger.debug("Houston, we have a problem. D/C"); c.disconnect(); throw new Exception(); } if (c.login("drftpd", "drftpd")) { logger.debug("Logged-in, now waiting 5 secs and kill the thread."); _sc.addSuccess(); Thread.sleep(5000); c.disconnect(); } else { logger.debug("Login failed, D/C!"); throw new Exception(); } } catch (Exception e) { logger.debug(e, e); _sc.addFailure(); } logger.debug("exiting"); }
Example #11
Source File: FTPSNetworkClient.java From FireFiles with Apache License 2.0 | 5 votes |
public FTPSNetworkClient(final String host, final int port, final String userName, final String password){ client = new FTPSClient(); this.host = host; this.port = port; this.username = userName; this.password = password; }
Example #12
Source File: FTPSNetworkClient.java From FireFiles with Apache License 2.0 | 5 votes |
public FTPSNetworkClient(final String host, final int port){ client = new FTPSClient(); this.host = host; this.port = port; this.username = "anonymous"; this.password = ""; }
Example #13
Source File: FTPSNetworkClient.java From FireFiles with Apache License 2.0 | 5 votes |
public FTPSNetworkClient(final String host, final int port, final String userName, final String password){ client = new FTPSClient(); this.host = host; this.port = port; this.username = userName; this.password = password; }
Example #14
Source File: FTPSNetworkClient.java From FireFiles with Apache License 2.0 | 5 votes |
public FTPSNetworkClient(final String host, final int port){ client = new FTPSClient(); this.host = host; this.port = port; this.username = "anonymous"; this.password = ""; }
Example #15
Source File: FTPSNetworkClient.java From FireFiles with Apache License 2.0 | 5 votes |
public FTPSNetworkClient(final String host, final int port, final String userName, final String password){ client = new FTPSClient(); this.host = host; this.port = port; this.username = userName; this.password = password; }
Example #16
Source File: FTPSNetworkClient.java From FireFiles with Apache License 2.0 | 5 votes |
public FTPSNetworkClient(final String host, final int port){ client = new FTPSClient(); this.host = host; this.port = port; this.username = "anonymous"; this.password = ""; }
Example #17
Source File: FTPUtils.java From TranskribusCore with GNU General Public License v3.0 | 4 votes |
public static void loginToFTP(FTPSClient ftp, String ftpUser, String ftpPw) throws IOException { if (!ftp.login(ftpUser, ftpPw)) { throw new IOException("Unable to login!"); } }
Example #18
Source File: MultipleConnectionTestCase.java From commons-vfs with Apache License 2.0 | 4 votes |
private FTPSClient init(final FTPSClient client) { client.enterLocalPassiveMode(); return client; }
Example #19
Source File: FtpsClientFactory.java From commons-vfs with Apache License 2.0 | 3 votes |
/** * Creates a new connection to the server. * * @param hostname The host name. * @param port The port. * @param username The user name for authentication. * @param password The user's password. * @param workingDirectory The directory to use. * @param fileSystemOptions The FileSystemOptions. * @return The FTPSClient. * @throws FileSystemException if an error occurs. */ public static FTPSClient createConnection(final String hostname, final int port, final char[] username, final char[] password, final String workingDirectory, final FileSystemOptions fileSystemOptions) throws FileSystemException { final FtpsConnectionFactory factory = new FtpsConnectionFactory(FtpsFileSystemConfigBuilder.getInstance()); return factory.createConnection(hostname, port, username, password, workingDirectory, fileSystemOptions); }
Example #20
Source File: FTPClientWrapper.java From JPPF with Apache License 2.0 | 3 votes |
/** * Open a secure ftp connection with the specified parameters. * @param host the host where the FTP server is running * @param port the secure FTP port. * @param user username to use. * @param password the user password. * @throws Exception if any error occurs. */ public void open(final String host, final int port, final String user, final String password) throws Exception { // create with implicit TLS ftpClient = new FTPSClient(true); ftpClient.connect(host, port); ftpClient.login(user, password); }
Example #21
Source File: FtpsClient.java From spring-boot with Apache License 2.0 | 2 votes |
public FtpsClient() { ftpClient = new FTPSClient(SSL, true); }