secureProtocol = FTPUploadTaskParameters.DEFAULT_SECURE_SOCKET_PROTOCOL; ftpClient = new FTPSClient(secureProtocol, ftpParams.implicitSecurity);
@Override protected void postProcessClientBeforeConnect(FTPSClient ftpsClient) throws IOException { if (StringUtils.hasText(this.authValue)) { ftpsClient.setAuthValue(this.authValue); ftpsClient.setTrustManager(this.trustManager); ftpsClient.setEnabledCipherSuites(this.cipherSuites); ftpsClient.setEnabledProtocols(this.protocols); ftpsClient.setEnabledSessionCreation(this.sessionCreation); ftpsClient.setUseClientMode(this.useClientMode); ftpsClient.setEnabledSessionCreation(this.sessionCreation); ftpsClient.setKeyManager(this.keyManager); ftpsClient.setNeedClientAuth(this.needClientAuth); ftpsClient.setWantClientAuth(this.wantsClientAuth);
/** * PBSZ command. pbsz value: 0 to (2^32)-1 decimal integer. * Issues the command and parses the response to return the negotiated value. * * @param pbsz Protection Buffer Size. * @throws SSLException If the server reply code does not equal "200". * @throws IOException If an I/O error occurs while sending * the command. * @return the negotiated value. * @see #execPBSZ(long) * @since 3.0 */ public long parsePBSZ(long pbsz) throws SSLException, IOException { execPBSZ(pbsz); long minvalue = pbsz; String remainder = extractPrefixedData("PBSZ=", getReplyString()); if (remainder != null) { long replysz = Long.parseLong(remainder); if (replysz < minvalue) { minvalue = replysz; } } return minvalue; }
FTPSClient ftpClient = new FTPSClient("TLS", false); try { TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() { ftpClient.setTrustManager(trustManager[0]); KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); kmf.init(null, null); KeyManager km = kmf.getKeyManagers()[0]; ftpClient.setKeyManager(km); ftpClient.setBufferSize(1024 * 1024); ftpClient.setConnectTimeout(100000); ftpClient.connect(InetAddress.getByName("ipaddress"), 990); ftpClient.setSoTimeout(100000); if (ftpClient.login("user", "password")) { ftpClient.execPBSZ(0); ftpClient.execPROT("P"); ftpClient.changeWorkingDirectory("/"); if (ftpClient.getReplyString().contains("250")) { ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); BufferedInputStream buffIn = null; boolean result = ftpClient.storeFile(picture.getName(), buffIn); try { buffIn.close(); } finally {
this.ftpClient = new FTPSClient(ftpsProtocol, ftpsIsImplicit); ftpClient.setTrustManager(defaultTrustManager); ftpClient.configure(new FTPClientConfig(systemKey)); this.ftpClient.setDefaultTimeout(this.connectionTimeout); ftpClient.connect(InetAddress.getByName(this.remoteHostname), this.remotePort); int reply = ftpClient.getReplyCode(); if(!FTPReply.isPositiveCompletion(reply)) ftpClient.execPBSZ(0); // Set protection buffer size ftpClient.execPROT("P"); // Set data channel protection to private ftpClient.execCCC(); this.ftpClient.enterLocalActiveMode(); } else { this.ftpClient.enterLocalPassiveMode(); this.ftpClient.setSoTimeout(this.socketTimeout); this.ftpClient.setDataTimeout(this.dataTimeout); break; if(this.ftpClient != null && this.ftpClient.isConnected()) this.ftpClient.disconnect();
@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; }
FTPSClient l_ftp = new FTPSClient("SSL", false); l_ftp.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); l_ftp.setAuthValue("SSL"); l_ftp.connect(l_host, l_port); if (!l_ftp.login(l_username, l_password)) { // BAD! } l_ftp.execPBSZ(0L); l_ftp.execCCC(); l_ftp.pwd(); // DO STUFF l_ftp.logout(); l_ftp.disconnect();
SSLContext context = sslContextParameters.createSSLContext(getCamelContext()); client = new FTPSClient(getFtpsConfiguration().isImplicit(), context); client.setEnabledCipherSuites(socket.getEnabledCipherSuites()); client.setEnabledProtocols(socket.getEnabledProtocols()); client.setNeedClientAuth(socket.getNeedClientAuth()); client.setWantClientAuth(socket.getWantClientAuth()); client.setEnabledSessionCreation(socket.getEnableSessionCreation()); } else { client = new FTPSClient(getFtpsConfiguration().getSecurityProtocol(), getFtpsConfiguration().isImplicit()); client.setNeedClientAuth(true); client.setKeyManager(keyMgrFactory.getKeyManagers()[0]); trustMgrFactory.init(trustStore); client.setTrustManager(trustMgrFactory.getTrustManagers()[0]);
FTPSClient ftpClient = new FTPSClient("tls",false); ftpClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); ftpClient.connect(host, port); int reply = ftpClient.getReplyCode(); if (FTPReply.isPositiveCompletion(reply)) { ftpClient.execPBSZ(0); reply = ftpClient.getReplyCode(); // Check for PBSZ error responses... ftpClient.execPROT("P"); reply = ftpClient.getReplyCode(); // Check for PROT error responses... ftpClient.enterLocalPassiveMode();
@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(); } } } }
public static void main(String[] args) { FTPSClient ftp = new FTPSClient(); String host = "server.com"; int port = 2121; String folderName = "dir"; String username = "user"; String password = "password"; try { ftp.connect(host, port); ftp.login(username, password); InputStream fis = new FileInputStream("../filename_src.txt"); ftp.storeFile("/" + folderName + "/filename_dest.xml", fis); fis.close(); ftp.logout(); ftp.disconnect(); } catch (SocketException ex) { Logger.getLogger(FTPSendMessage.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(FTPSendMessage.class.getName()).log(Level.SEVERE, null, ex); } }
FTPSClient mFtps = new FTPSClient(); mFtps.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager());
this.ftpsConnection = new org.apache.commons.net.ftp.FTPSClient(this.implicit, sslContext); this.ftpsConnection.addProtocolCommandListener( ((FtpResponseListener) listener)); this.ftpsConnection.addProtocolCommandListener(new FtpListener()); this.ftpsConnection.setConnectTimeout(this.timeout); this.ftpsConnection.connect(hostname, this.port); if (!this.ftpsConnection.login(userName, password)) { throw new Exception("Invallid username and/or password. "); if (!this.ftpsConnection.setFileType(org.apache.commons.net.ftp.FTPSClient.ASCII_FILE_TYPE)) { throw new Exception("Unable to set transfer mode to ASCII"); if (!this.ftpsConnection.setFileType(org.apache.commons.net.ftp.FTPSClient.BINARY_FILE_TYPE)) { throw new Exception("Unable to set transfer mode to BINARY");
setConnected(true); try { ftpsClient.connect(getServer(), getPort()); int replyCode = ftpsClient.getReplyCode(); ftpsClient.disconnect(); LOGGER.error("Connect Failed due to FTPS, server refused connection."); this.setConnected(false); if (!(ftpsClient.login(user, password))) { LOGGER.error("Could not login to the server"); this.setConnected(false); ftpsClient.enterLocalPassiveMode(); ftpsClient.setControlKeepAliveTimeout(300); if (getWorkingDirectory() != null) { ftpsClient.changeWorkingDirectory(getWorkingDirectory()); ftpsClient.setBufferSize(getBufferSize());
@Override public boolean connectClient() throws IOException { boolean isLoggedIn = true; client.setAutodetectUTF8(true); client.setControlEncoding("UTF-8"); client.connect(host, port); client.setFileType(FTP.BINARY_FILE_TYPE); client.enterLocalPassiveMode(); client.login(username, password); int reply = client.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { client.disconnect(); LogUtils.LOGD(TAG, "Negative reply form FTP server, aborting, id was {}:"+ reply); //throw new IOException("failed to connect to FTP server"); isLoggedIn = false; } return isLoggedIn; }
FTPSClient ftpClient = new FTPSClient(); ftpClient.connect(host); ftpClient.login(user, password);
@Override protected FTPClient createClient() { LOG.debug( "Creating secure FTP client. Protocol: [{}], implicit mode: [{}], endpoint checking: [{}].", securityProtocol, implicit, endpointChecking ); FTPSClient client = new FTPSClient( securityProtocol, implicit ); client.setEndpointCheckingEnabled( endpointChecking ); return client; } }
/** * @void, check if trust all certifcates. */ public void checkIfCertificate() { if (securityCert) { ftpsClient.setTrustManager(TrustManagerUtils.getValidateServerCertificateTrustManager()); KeyManager keyManager = null; try { keyManager = KeyManagerUtils.createClientKeyManager(new File(pathTokesytore), storePass); } catch (IOException e) { LOGGER.error("", e); } catch (GeneralSecurityException e) { LOGGER.error("",e); } ftpsClient.setKeyManager(keyManager); } else { ftpsClient.setTrustManager(TrustManagerUtils.getAcceptAllTrustManager()); } }
/** * Disconnect and logout from current connection to server * */ @Override public void disconnect() { try { ftpsClient.logout(); ftpsClient.disconnect(); setConnected(false); } catch (IOException e) { LOGGER.error("Source " + this.getClass().getName() + " failed disconnect", e); } }