List of usage examples for org.apache.commons.net.ftp FTPFile isFile
public boolean isFile()
From source file:org.mule.transport.ftp.FtpMessageRequester.java
protected FTPFile findFileToProcess(FTPClient client) throws Exception { FTPListParseEngine engine = client.initiateListParsing(); FTPFile[] files = null;//from w ww. j a va2 s. com while (engine.hasNext()) { files = engine.getNext(FTP_LIST_PAGE_SIZE); if (files == null) { break; } FilenameFilter filenameFilter = getFilenameFilter(); for (int i = 0; i < files.length; i++) { FTPFile file = files[i]; if (file.isFile()) { if (filenameFilter.accept(null, file.getName())) { if (connector.validateFile(file)) { // only read the first one return file; } } } } } if (!FTPReply.isPositiveCompletion(client.getReplyCode())) { throw new IOException("Ftp error: " + client.getReplyCode()); } return null; }
From source file:org.mule.transport.ftps.FtpsMessageReceiver.java
protected FTPFile[] listFiles() throws Exception { FTPSClient client = null;//from w w w. j a v a 2 s. com try { client = connector.createFTPSClient(endpoint); FTPListParseEngine engine = client.initiateListParsing(); FTPFile[] files = null; List<FTPFile> v = new ArrayList<FTPFile>(); while (engine.hasNext()) { if (getLifecycleState().isStopping()) { break; } files = engine.getNext(FTP_LIST_PAGE_SIZE); if (files == null || files.length == 0) { return files; } for (FTPFile file : files) { if (file.isFile()) { if (filenameFilter == null || filenameFilter.accept(null, file.getName())) { v.add(file); } } } } if (!FTPReply.isPositiveCompletion(client.getReplyCode())) { throw new IOException("Failed to list files. Ftp error: " + client.getReplyCode()); } return v.toArray(new FTPFile[v.size()]); } finally { if (client != null) { connector.releaseFtp(endpoint.getEndpointURI(), client); } } }
From source file:org.mule.transport.ftps.FtpsMessageRequester.java
protected FTPFile findFileToProcess(FTPSClient client) throws Exception { //Checking if it is a file or a directory boolean isFile = connector.isFile(endpoint, client); FTPListParseEngine engine = client.initiateListParsing(); FTPFile[] files = null;// w w w .ja v a 2 s . co m while (engine.hasNext()) { files = engine.getNext(FTP_LIST_PAGE_SIZE); if (files == null) { break; } FilenameFilter filenameFilter = getFilenameFilter(); for (int i = 0; i < files.length; i++) { FTPFile file = files[i]; if (file.isFile() && isValid(file, filenameFilter)) { // only read the first one return file; } } } if (!FTPReply.isPositiveCompletion(client.getReplyCode())) { throw new IOException("Ftp error: " + client.getReplyCode()); } return null; }
From source file:org.openo.commontosca.catalog.ftp.FtpUtil.java
/** * download ftp file.// w w w. j a v a2s .com * * @param ftpFile ftp file to download * @param relativeLocalPath relative local path * @param relativeRemotePath relative remote path */ private static void downloadFile(FTPFile ftpFile, String relativeLocalPath, String relativeRemotePath) { if (ftpFile.isFile()) { if (ftpFile.getName().indexOf("?") == -1) { OutputStream outputStream = null; try { File locaFile = new File(relativeLocalPath + ftpFile.getName()); if (locaFile.exists()) { return; } else { outputStream = new FileOutputStream(relativeLocalPath + ftpFile.getName()); ftp.retrieveFile(ftpFile.getName(), outputStream); outputStream.flush(); outputStream.close(); } } catch (Exception e1) { logger.error(e1); } finally { try { if (outputStream != null) { outputStream.close(); } } catch (IOException e1) { logger.error("OutputStream error !"); } } } } else { String newlocalRelatePath = relativeLocalPath + ftpFile.getName(); String newRemote = new String(relativeRemotePath + ftpFile.getName().toString()); File fl = new File(newlocalRelatePath); if (!fl.exists()) { fl.mkdirs(); } try { newlocalRelatePath = newlocalRelatePath + '/'; newRemote = newRemote + "/"; String currentWorkDir = ftpFile.getName().toString(); boolean changedir = ftp.changeWorkingDirectory(currentWorkDir); if (changedir) { FTPFile[] files = null; files = ftp.listFiles(); for (int i = 0; i < files.length; i++) { downloadFile(files[i], newlocalRelatePath, newRemote); } } if (changedir) { ftp.changeToParentDirectory(); } } catch (Exception e1) { logger.error(e1); } } }
From source file:org.openspice.vfs.ftp.FtpVFolder.java
private List list(final boolean want_folders, final boolean want_files) { // System.err.println( "folders = " + want_folders ); // System.err.println( "files = " + want_files ); try {/*from w w w . j a v a 2 s .c o m*/ final FTPClient ftpc = this.fvol.getConnectedFTPClient(); final FTPFile[] files = ftpc.listFiles(this.path); // { // System.err.println( "List of files is " + files.length + " long" ); // for ( int n = 0; n < files.length; n++ ) { // System.err.println( "["+n+"]. " + files[n] + " " + ( files[n].isDirectory() ? "d" : "-" ) + ( files[n].isFile() ? "f" : "-" ) ); // } // } final List answer = new ArrayList(); for (int i = 0; i < files.length; i++) { final FTPFile file = files[i]; if (want_folders && file.isDirectory()) { // System.err.println( "adding FOLDER " + file ); answer.add(new FtpVFolder(this.fvol, FtpTools.folderName(this.path, file.getName()))); } else if (want_files && (file.isFile() || file.isSymbolicLink())) { // System.err.println( "adding FILE " + file ); answer.add(FtpVFile.uncheckedMake(this.fvol, FtpTools.fileName(this.path, file.getName()))); } } return answer; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.oss.bonita.utils.ftp.FtpTransfer.java
public boolean fileExists(FTPFile[] ftpFiles, String fileName) { if (ftpFiles != null && ftpFiles.length > 0) { for (FTPFile file : ftpFiles) { if (file.isFile()) { if (fileName.equals(file.getName())) { return true; }/* www. j a v a 2 s . c o m*/ } } } return false; }
From source file:org.oss.bonita.utils.ftp.FtpTransfer.java
public boolean folderExists(FTPFile[] ftpFiles, String FolderName) { if (ftpFiles != null && ftpFiles.length > 0) { for (FTPFile file : ftpFiles) { if (!file.isFile()) { if (FolderName.equals(file.getName())) { return true; }// w w w .j av a 2 s. c om } } } return false; }
From source file:org.sipfoundry.sipxconfig.admin.ftp.FtpContextImpl.java
private void delete(FTPFile... files) { try {//from w w w.j av a2s . com for (FTPFile file : files) { if (file.isFile()) { m_client.deleteFile(file.getName()); } else if (file.isDirectory()) { changeDirectory(file.getName()); delete(m_client.listFiles()); changeDirectory(UP); m_client.removeDirectory(file.getName()); } } } catch (IOException e) { LOG.error(e); throw new UserException(INTERNAL_FTP_ERROR); } }
From source file:org.sipfoundry.sipxconfig.admin.ftp.FtpContextImpl.java
private void download(String locationPath, FTPFile... files) { try {/*w ww . j av a2s. co m*/ for (FTPFile file : files) { if (file.isFile()) { OutputStream output = new FileOutputStream(locationPath + File.separator + file.getName()); m_client.retrieveFile(file.getName(), output); output.close(); } else if (file.isDirectory()) { changeDirectory(file.getName()); File fileNew = new File(locationPath + File.separator + file.getName()); fileNew.mkdir(); download(locationPath + File.separator + file.getName(), m_client.listFiles()); changeDirectory(UP); } } } catch (IOException e) { LOG.error(e); throw new UserException(INTERNAL_FTP_ERROR); } }
From source file:org.springframework.integration.ftp.inbound.FtpInboundFileSynchronizer.java
@Override protected boolean isFile(FTPFile file) { return file != null && file.isFile(); }