List of usage examples for org.apache.commons.net.ftp FTPSClient getReplyString
public String getReplyString()
From source file:IHM.FenetreAjoutAffiche.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed try {//from w w w. j a v a 2 s. co m FileInputStream input = null; try { input = new FileInputStream(nomF); } catch (FileNotFoundException ex) { Logger.getLogger(FenetreAjoutPhoto.class.getName()).log(Level.SEVERE, null, ex); } FTPSClient ftpClient = new FTPSClient(); ftpClient.connect("iutdoua-samba.univ-lyon1.fr", 990); Properties props = new Properties(); FileInputStream fichier = new FileInputStream("src/info.properties"); props.load(fichier); ftpClient.login(props.getProperty("login"), props.getProperty("password")); System.out.println(ftpClient.getReplyString()); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); String remote; remote = "public_html/CPOA/Site/assets/affichesFilm/" + txtNomPhoto.getText(); boolean done = ftpClient.storeFile(remote, input); input.close(); if (done) { System.out.println("reussi"); this.affiche.setNom(txtNomPhoto.getText()); etat = true; this.dispose(); } else { System.out.println(ftpClient.getReplyString()); this.dispose(); } } catch (IOException ex) { Logger.getLogger(FenetreAjoutPhoto.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:IHM.FenetreAjoutPhoto.java
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed try {/*from ww w . j a va 2s. c o m*/ FileInputStream input = null; try { input = new FileInputStream(nomF); } catch (FileNotFoundException ex) { Logger.getLogger(FenetreAjoutPhoto.class.getName()).log(Level.SEVERE, null, ex); } FTPSClient ftpClient = new FTPSClient(); ftpClient.connect("iutdoua-samba.univ-lyon1.fr", 990); Properties props = new Properties(); FileInputStream fichier = new FileInputStream("src/info.properties"); props.load(fichier); ftpClient.login(props.getProperty("login"), props.getProperty("password")); // on tablit les paramtre de connexion et on fournit les identifiants System.out.println(ftpClient.getReplyString()); ftpClient.setFileType(FTP.BINARY_FILE_TYPE); ftpClient.setFileTransferMode(FTP.BINARY_FILE_TYPE); ftpClient.enterLocalPassiveMode(); String remote = null; if (this.radioBtnPhoto.isSelected()) //si l'utilisateur beut choisir une photo classique on choisit le bon rpertoire d'arriver { remote = "public_html/CPOA/Site/assets/photos/" + txtNomPhoto.getText(); this.laPhoto.setTypePhoto(1); } else if ((this.radioBtnPhotoP.isSelected())) // de mme si c'est une photo de profil { remote = "public_html/CPOA/Site/assets/photoProfil/" + txtNomPhoto.getText(); this.laPhoto.setTypePhoto(2); } boolean done = ftpClient.storeFile(remote, input); // on upload la photo input.close(); if (done) // on teste si le transfert est russi { System.out.println("reussi"); this.laPhoto.setNomPhoto(txtNomPhoto.getText()); this.laPhoto.setLieu(txtLieu.getText()); String dateD = txtAnneeD.getText() + "-" + txtMoisD.getText() + "-" + txtJourD.getText(); this.laPhoto.setDatePhoto(dateD); etat = true; this.dispose(); } else { System.out.println(ftpClient.getReplyString()); // on affiche la rponse du serveur si le transfert est rat this.dispose(); } } catch (IOException ex) { Logger.getLogger(FenetreAjoutPhoto.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.claim.controller.FileTransferController.java
public boolean uploadMutiFilesWithFTPS(ObjFileTransfer ftpObj) throws Exception { FTPSClient ftpsClient = null; int replyCode; boolean completed = false; try {// ww w.ja va 2 s . c om FtpProperties properties = new ResourcesProperties().loadFTPProperties(); try { ftpsClient = new FTPSClient(properties.getFtp_protocal(), properties.isFtp_impicit()); //ftpsClient.setAuthValue(ConstantFtp.FTPS_PROTOCAL); ftpsClient.setDataTimeout(ConstantFtp.FTP_TIMEOUT); ftpsClient.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out))); System.out.print(ftpsClient.getReplyString()); ftpsClient.connect(properties.getFtp_server(), properties.getFtp_port()); FtpUtil.showServerReply(ftpsClient); } catch (ConnectException ex) { FtpUtil.showServerReply(ftpsClient); Console.LOG(ex.getMessage(), 0); System.out.println("ConnectException: " + ex.getMessage()); ex.printStackTrace(); } catch (SocketException ex) { FtpUtil.showServerReply(ftpsClient); Console.LOG(ex.getMessage(), 0); System.out.println("SocketException: " + ex.getMessage()); ex.printStackTrace(); } catch (UnknownHostException ex) { FtpUtil.showServerReply(ftpsClient); Console.LOG(ex.getMessage(), 0); System.out.println("UnknownHostException: " + ex.getMessage()); ex.printStackTrace(); } replyCode = ftpsClient.getReplyCode(); FtpUtil.showServerReply(ftpsClient); if (!FTPReply.isPositiveCompletion(replyCode)) { ftpsClient.disconnect(); Console.LOG("Exception in connecting to FTP Serve ", 0); throw new Exception("Exception in connecting to FTP Server"); } else { Console.LOG("Success in connecting to FTP Serve ", 1); } try { boolean success = ftpsClient.login(properties.getFtp_username(), properties.getFtp_password()); FtpUtil.showServerReply(ftpsClient); if (!success) { throw new Exception("Could not login to the FTP server."); } else { Console.LOG("login to the FTP server. Successfully ", 1); } //ftpClient.enterLocalPassiveMode(); } catch (FTPConnectionClosedException ex) { Console.LOG(ex.getMessage(), 0); FtpUtil.showServerReply(ftpsClient); System.out.println("Error: " + ex.getMessage()); ex.printStackTrace(); } ftpsClient.setFileType(FTP.BINARY_FILE_TYPE); ftpsClient.execPBSZ(0); //FTP_REMOTE_HOME = ftpClient.printWorkingDirectory(); String workingDirectoryReportType = properties.getFtp_remote_directory() + File.separator + ftpObj.getFtp_report_type(); FtpUtil.ftpCreateDirectoryTree(ftpsClient, workingDirectoryReportType); FtpUtil.showServerReply(ftpsClient); String workingDirectoryStmp = workingDirectoryReportType + File.separator + ftpObj.getFtp_stmp(); FtpUtil.ftpCreateDirectoryTree(ftpsClient, workingDirectoryStmp); FtpUtil.showServerReply(ftpsClient); // APPROACH #2: uploads second file using an OutputStream File files = new File(ftpObj.getFtp_directory_path()); for (File file : files.listFiles()) { if (file.isFile()) { System.out.println("file ::" + file.getName()); InputStream in = new FileInputStream(file); ftpsClient.changeWorkingDirectory(workingDirectoryStmp); completed = ftpsClient.storeFile(file.getName(), in); in.close(); Console.LOG( " " + file.getName() + " ", 1); FtpUtil.showServerReply(ftpsClient); } } Console.LOG(" ?... ", 1); //completed = ftpClient.completePendingCommand(); FtpUtil.showServerReply(ftpsClient); completed = true; ftpsClient.disconnect(); } catch (IOException ex) { Console.LOG(ex.getMessage(), 0); FtpUtil.showServerReply(ftpsClient); System.out.println("Error: " + ex.getMessage()); ex.printStackTrace(); } finally { try { if (ftpsClient.isConnected()) { ftpsClient.logout(); ftpsClient.disconnect(); } } catch (IOException ex) { FtpUtil.showServerReply(ftpsClient); Console.LOG(ex.getMessage(), 0); ex.printStackTrace(); } } return completed; }
From source file:org.mule.transport.ftps.FtpsConnector.java
/** * Well get the output stream (if any) for this type of transport. Typically this * will be called only when Streaming is being used on an outbound endpoint * * @param endpoint the endpoint that releates to this Dispatcher * @param event the current event being processed * @return the output stream to use for this request or null if the transport * does not support streaming//from w w w .j av a 2 s. com */ @Override public OutputStream getOutputStream(OutboundEndpoint endpoint, MuleEvent event) throws MuleException { try { final EndpointURI uri = endpoint.getEndpointURI(); String filename = getFilename(endpoint, event.getMessage()); final FTPSClient client; try { client = this.createFTPSClient(endpoint); } catch (Exception e) { throw new ConnectException(e, this); } try { OutputStream out = client.storeFileStream(filename); if (out == null) { throw new IOException("FTP operation failed: " + client.getReplyString()); } return new CallbackOutputStream(out, new CallbackOutputStream.Callback() { public void onClose() throws Exception { try { if (!client.completePendingCommand()) { client.logout(); client.disconnect(); throw new IOException("FTP Stream failed to complete pending request"); } } finally { releaseFtp(uri, client); } } }); } catch (Exception e) { logger.debug("Error getting output stream: ", e); releaseFtp(uri, client); throw e; } } catch (ConnectException ce) { // Don't wrap a ConnectException, otherwise the retry policy will not go into effect. throw ce; } catch (Exception e) { throw new DispatchException(CoreMessages.streamingFailedNoStream(), event, endpoint, e); } }