List of usage examples for org.apache.commons.net.ftp FTPSClient execPROT
public void execPROT(String prot) throws SSLException, IOException
From source file:com.logic.test.FTPSLogic.java
public static void main(String[] args) { String serverAdress = "62.2.176.167"; String username = "RLSFTPRead"; String password = "ftp4rls"; int port = 990; FTPSClient ftpsClient = new FTPSClient("TLS", true); String remoteFile = "REM - Persons Extract.csv"; File localFile = new File("Persons Extract.csv"); try {/*from w w w .j a v a2s . c o m*/ TrustManager[] trustManager = new TrustManager[] { new X509TrustManager() { @Override public X509Certificate[] getAcceptedIssuers() { return null; } @Override public void checkClientTrusted(X509Certificate[] certs, String authType) { } @Override public void checkServerTrusted(X509Certificate[] certs, String authType) { } } }; ftpsClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); //ftpsClient.setTrustManager(trustManager[0]); //KeyManagerFactory kmf = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm()); //kmf.init(null, null); //KeyManager km = kmf.getKeyManagers()[0]; //ftpsClient.setKeyManager(km); ftpsClient.setBufferSize(1024 * 1024); ftpsClient.setConnectTimeout(100000); ftpsClient.connect(InetAddress.getByName(serverAdress), port); ftpsClient.setSoTimeout(100000); if (ftpsClient.login(username, password)) { ftpsClient.execPBSZ(0); ftpsClient.execPROT("P"); ftpsClient.changeWorkingDirectory("/"); ftpsClient.setFileType(FTP.BINARY_FILE_TYPE); ftpsClient.enterLocalPassiveMode(); //ftpsClient.retrieveFile(remoteFile, new FileOutputStream(localFile)); for (FTPFile file : ftpsClient.listFiles()) { System.out.println("Nom " + file.getName()); } } } catch (SocketException e) { ; } catch (UnknownHostException e) { ; } catch (IOException e) { ; } catch (Exception e) { ; } finally { try { ftpsClient.logout(); } catch (Exception e2) { } try { ftpsClient.disconnect(); } catch (Exception e2) { } } }
From source file:com.adaptris.ftp.CommonsNetFtpSslClient.java
@Override protected void postConnectSettings(FTPSClient client) throws IOException { // With ImplicitSSL we still need to set the protection level; as by default // the data channel is "Clear"... // Set protection buffer size client.execPBSZ(0);//from ww w . ja v a2s . c om // Set data channel protection to private client.execPROT("P"); }
From source file:org.springframework.integration.ftp.session.DefaultFtpsSessionFactory.java
@Override protected void postProcessClientAfterConnect(FTPSClient ftpsClient) throws IOException { ftpsClient.execPBSZ(0);// w w w . j a v a 2s. co m ftpsClient.execPROT(this.prot); }
From source file:org.teiid.resource.adapter.ftp.FtpManagedConnectionFactory.java
private void beforeConnectProcessing(FTPClient client) throws IOException { client.configure(this.config); if (this.connectTimeout != null) { client.setConnectTimeout(this.connectTimeout); }// w ww . j av a 2 s.c o m if (this.defaultTimeout != null) { client.setDefaultTimeout(this.defaultTimeout); } if (this.dataTimeout != null) { client.setDataTimeout(this.dataTimeout); } client.setControlEncoding(this.controlEncoding); if (this.isFtps) { FTPSClient ftpsClient = (FTPSClient) client; ftpsClient.execPBSZ(0); ftpsClient.execPROT(this.execProt); } }
From source file:org.wso2.iot.agent.services.FileDownloadService.java
/** * This method downloads the file using sftp client. * * @param operation - operation object. * @param host - host address. * @param ftpUserName - ftp user name. * @param ftpPassword - ftp password. * @param savingLocation - location in the device to save the file. * @param fileName - name of the file to download. * @param serverPort - ftp server port. * @param fileDirectory - the directory of the file in FTP server. * @throws AndroidAgentException - Android agent exception. *//*from www . j av a2s .c o m*/ private void downloadFileUsingFTPSClient(Operation operation, String host, String ftpUserName, String ftpPassword, String savingLocation, String fileName, int serverPort, String fileDirectory) throws AndroidAgentException { FTPSClient ftpsClient = new FTPSClient(); FileOutputStream fileOutputStream = null; OutputStream outputStream = null; String response; try { ftpsClient.connect(host, serverPort); if (ftpsClient.login(ftpUserName, ftpPassword)) { ftpsClient.enterLocalPassiveMode(); ftpsClient.execPROT("P"); fileOutputStream = new FileOutputStream(savingLocation + File.separator + fileName); outputStream = new BufferedOutputStream(fileOutputStream); ftpsClient.changeWorkingDirectory(fileDirectory); if (ftpsClient.retrieveFile(fileName, outputStream)) { response = "File uploaded to the device successfully ( " + fileName + " )."; operation.setStatus(resources.getString(R.string.operation_value_completed)); } else { response = "File uploaded to the device not completed ( " + fileName + " )."; operation.setStatus(resources.getString(R.string.operation_value_error)); } } else { response = ftpUserName + " - FTP login failed."; operation.setStatus(resources.getString(R.string.operation_value_error)); } operation.setOperationResponse(response); } catch (IOException e) { handleOperationError(operation, fileTransferExceptionCause(e, fileName), e); } finally { try { if (ftpsClient.isConnected()) { ftpsClient.logout(); ftpsClient.disconnect(); } } catch (IOException ignored) { } cleanupStreams(null, outputStream, null, fileOutputStream, null, null, null, null); } }
From source file:org.wso2.iot.agent.services.FileUploadService.java
/** * File upload operation using an FTPS explicit TLS client. * * @param operation - operation object. * @param host - host name./*from ww w. ja v a2 s.co m*/ * @param ftpUserName - ftp user name. * @param ftpPassword - ftp password. * @param uploadDirectory - ftp directory to upload file. * @param fileLocation - local file location. * @param serverPort - ftp port to connect. * @throws AndroidAgentException - AndroidAgent exception. */ private void uploadFileUsingFTPSClient(Operation operation, String host, String ftpUserName, String ftpPassword, String uploadDirectory, String fileLocation, int serverPort) throws AndroidAgentException { FTPSClient ftpsClient = new FTPSClient(); String fileName = null; InputStream inputStream = null; Boolean loginResult = false; String response; try { File file = new File(fileLocation); fileName = file.getName(); ftpsClient.connect(host, serverPort); ftpsClient.enterLocalPassiveMode(); loginResult = ftpsClient.login(ftpUserName, ftpPassword); ftpsClient.execPROT("P"); inputStream = new FileInputStream(file); ftpsClient.changeWorkingDirectory(uploadDirectory); if (ftpsClient.storeFile(fileName, inputStream)) { response = "File uploaded from the device completed ( " + fileName + " )."; operation.setStatus(resources.getString(R.string.operation_value_completed)); } else { response = "File uploaded from the device not completed ( " + fileName + " )."; operation.setStatus(resources.getString(R.string.operation_value_error)); } operation.setOperationResponse(response); } catch (IOException e) { if (!loginResult) { response = ftpUserName + " - FTP login failed."; } else { response = fileTransferExceptionCause(e, fileName); } handleOperationError(operation, response, e, resources); } finally { try { if (ftpsClient.isConnected()) { ftpsClient.logout(); ftpsClient.disconnect(); } } catch (IOException ignored) { } cleanupStreams(inputStream, null, null, null, null, null, null, null); } }