/*** * * @param filePattern * @throws IOException */ @SuppressWarnings("unchecked") public void del(String filePattern) throws IOException { final FilenameFilter filter = FileNamePatternUtil.buildFileNameFilterFromWildCard(filePattern); final List<SftpFile> fileContainedWithinWorkingDir = client.ls(); // Retrieve the files that match the given name for (SftpFile file : fileContainedWithinWorkingDir) { if ((file.isFile() && file.canRead()) && filter.accept(null, file.getFilename())) { file.delete(); break; } } }
/** * Retrieve the specified files from the SSH server. * * @param fileFilterList * the list of files to get from the SFTP server * @return fhe files specified in the list * @throws IOException * if any IO problem occur while sending file or connecting to server */ @SuppressWarnings("unchecked") public Map<String, DataHandler> mGet(final List<String> fileFilterList) throws IOException { // Holds the result of the MGET operation final Map<String, DataHandler> dataHandlers = new HashMap<String, DataHandler>(); // Performs the MGET operation // Construct the fileFilters to match files read from the FTP // directory final List<FilenameFilter> filterList = new LinkedList<>(); for (final String string : fileFilterList) { filterList.add(FileNamePatternUtil.buildFileNameFilterFromWildCard(string)); } final FilenameFilter filter = FileNamePatternUtil.buildFileNameFilterFromFilters(filterList); final List<SftpFile> filesContainedWithinWorkingDir = client.ls(); for (SftpFile file : filesContainedWithinWorkingDir) { if ((file.isFile() && file.canRead()) && filter.accept(null, file.getFilename())) { dataHandlers.put(file.getFilename(), this.getAsDataHandler(file, client)); } } return dataHandlers; }
/** * Retrieve the file given by its filename on the SFTP server. * * @param filePattern * name of the file to get from the SFTP server * @return the retrieved file, streamed * @throws IOException * if any IO problem occur while sending file or connecting to * server */ @SuppressWarnings("unchecked") public Document get(final String filePattern) throws IOException { final FilenameFilter filter = FileNamePatternUtil.buildFileNameFilterFromWildCard(filePattern); // Holds the result of the GET operation Document result = null; final List<SftpFile> fileContainedWithinWorkingDir = client.ls(); for (SftpFile file : fileContainedWithinWorkingDir) { if ((file.isFile() && file.canRead()) && filter.accept(null, file.getFilename())) { result = this.getAsDocument(file, client); break; } } // If the file doen't exist if (result == null) { throw new IOException("Can not find the specified resource"); } return result; }
/** * Retrieve the file given by its filename on the SFTP server. * * @param filePattern * name of the file to get from the SFTP server * @return the retrieved file * @throws IOException * if any IO problem occur while sending file or connecting to * server */ @SuppressWarnings("unchecked") public DataHandler getAsAttachment(final String filePattern) throws IOException { final FilenameFilter filter = FileNamePatternUtil.buildFileNameFilterFromWildCard(filePattern); // Holds the result of the GET operation DataHandler retrievedFile = null; // Retrieve all the files from the current directory List<SftpFile> fileContainedWithinWorkingDir = client.ls(); // Retrieve the files that match the given name for (SftpFile file : fileContainedWithinWorkingDir) { if ((file.isFile() && file.canRead()) && filter.accept(null, file.getFilename())) { retrievedFile = this.getAsDataHandler(file, client); break; } } // If the file doen't exist if (retrievedFile == null) { throw new IOException("File not found"); } return retrievedFile; }
/** * create from SftpFile * @param l */ public ResourcesItem(SftpFile l) { setName(l.getFilename()); setLongName(l.getLongname()); setCanRead(l.canRead()); setCanWrite(l.canWrite()); setSize(l.getAttributes().getSize().longValue()); setFullName(l.getAbsolutePath()); }