List of usage examples for org.apache.commons.net.ftp FTPFile getName
public String getName()
From source file:com.knowbout.epg.processor.Downloader.java
public int downloadFiles() throws IOException { connect();/*w ww. ja v a 2s. c om*/ int downloads = 0; try { log.debug("DownloadFiles, about to list files"); FTPFile[] files = client.listFiles(); log.debug("Filelisting: " + files.length); for (FTPFile file : files) { log.debug("About to download the file: " + file.getName()); if (downloadFile(file)) { downloads++; } } } finally { disconnect(); } return downloads; }
From source file:com.webarch.common.net.ftp.FtpService.java
/** * /*from w w w . j a v a2s . c o m*/ * * @param remotePath ftp * @param fileName ??? * @param localPath ??? * @return true/false ? */ public boolean downloadFile(String remotePath, String fileName, String localPath) { boolean success = false; FTPClient ftpClient = new FTPClient(); try { int replyCode; ftpClient.connect(url, port); ftpClient.login(userName, password); replyCode = ftpClient.getReplyCode(); if (!FTPReply.isPositiveCompletion(replyCode)) { return false; } ftpClient.changeWorkingDirectory(remotePath); FTPFile[] files = ftpClient.listFiles(); for (FTPFile file : files) { if (file.getName().equals(fileName)) { File localFile = new File(localPath + File.separator + file.getName()); OutputStream outputStream = new FileOutputStream(localFile); ftpClient.retrieveFile(file.getName(), outputStream); outputStream.close(); } } ftpClient.logout(); success = true; } catch (IOException e) { logger.error("ftp?", e); } finally { if (ftpClient.isConnected()) { try { ftpClient.disconnect(); } catch (IOException e) { logger.error("ftp?", e); } } } return success; }
From source file:de.idos.updates.install.FtpInstallerTest.java
@Test public void reportsInstallation() throws Exception { FTPFile ftpFile = new FTPFile(); ftpFile.setName("name"); ftpInstaller.installElement(ftpFile, version); verify(report).installingFile(ftpFile.getName()); }
From source file:fr.chaffottem.bonita.connector.ftp.RemoveDirectoriesConnector.java
private boolean removeDirectory(final String pathDir) throws IOException { final FTPFile[] files = getFTPClient().listFiles(pathDir); for (final FTPFile file : files) { final StringBuilder pathBuilder = new StringBuilder(pathDir); pathBuilder.append("/").append(file.getName()); if (file.isDirectory()) { removeDirectory(pathBuilder.toString()); } else {/*from w w w. j ava 2s. c om*/ getFTPClient().deleteFile(pathBuilder.toString()); } } return getFTPClient().removeDirectory(pathDir); }
From source file:ftp.search.Index.java
private void insertFiles(String ftp, String path, Statement stmt, FTPClient ftpClient) throws IOException, SQLException { FTPFile[] files = ftpClient.listFiles(path); for (FTPFile file : files) { String details = file.getName(); String details2 = details.replace("'", "''"); String path2 = ftp + path; String path3 = path2.replace("'", "''"); int isDir = 0; if (file.isDirectory()) { isDir = 1;/* w w w .jav a 2s . c om*/ } String query = "INSERT INTO fileindex (FileName,path,Folder) VALUES ('" + details2 + "' , '" + path3 + "' , " + isDir + ")"; System.out.println(query); stmt.executeUpdate(query); if (isDir == 1) { if (!path.contains("Games") && !(path.contains("College")) && !(path.contains("Cricket")) && !(path.contains("GeekHaven")) && !(path.contains("Windows")) && !(path.contains("Win")) && !(path.contains("Linux")) && !path.contains("INDEM") && !(path.contains("Telugu"))) { insertFiles(ftp, path + details + "/", stmt, ftpClient); } } } }
From source file:car.PasserelleRestTest.java
/** * test de la mthode list directory//from w w w . j a v a2s . c om * Test que tous les fichiers prsent dans le dossier du ftp sont eux aussi prsent * */ @Test public void listDirectory() throws Exception { /* verifie que le formulaire ets bien prsent */ String resp = this.sendRequest("http://localhost:8080/rest/api/rest/list/"); /* on recupere les fichiers prsent dans le dossier et on verifie qu'ils sont tous renvoy par la paserelle */ for (FTPFile file : this.files) { if (!file.getName().equals(".")) if (!file.getName().equals("..")) assertTrue(resp.contains(file.getName())); } /* on verifie que les rponses ne sont pas toujours oui */ assertFalse(resp.contains("grrr.txt")); }
From source file:ca.ualberta.physics.cssdp.file.remote.protocol.FtpConnection.java
@Override public List<RemoteFile> ls(String path) { logger.debug("Listing files at " + path); try {//from w w w .j a v a2 s. c om ftpClient.enterLocalPassiveMode(); FTPFile[] files = ftpClient.listFiles(path); if (files == null || files.length == 0) { return new ArrayList<RemoteFile>(); } List<RemoteFile> list = new ArrayList<RemoteFile>(); for (FTPFile file : files) { String name = file.getName(); long size = file.getSize(); boolean isDir = file.isDirectory(); LocalDateTime modifiedTstamp = new LocalDateTime(file.getTimestamp()); RemoteFile remoteFile = new RemoteFile("ftp://" + getHostEntry().getHostname() + path + "/" + name, size, modifiedTstamp, isDir); list.add(remoteFile); } return list; } catch (SocketTimeoutException timeout) { throw new ProtocolException("Timedout listing " + path, true, timeout); } catch (IOException e) { throw new ProtocolException("Could not get file listing for " + path, false, e); } }
From source file:it.zero11.acme.example.FTPChallengeListener.java
private void deleteChallengeFiles() { FTPClient ftp = new FTPClient(); try {/*www . j a v a 2s .com*/ ftp.connect(host); if (!FTPReply.isPositiveCompletion(ftp.getReplyCode())) { ftp.disconnect(); return; } ftp.login(username, password); ftp.changeWorkingDirectory(webroot); ftp.changeWorkingDirectory(".well-known"); ftp.changeWorkingDirectory("acme-challenge"); FTPFile[] subFiles = ftp.listFiles(); if (subFiles != null && subFiles.length > 0) { for (FTPFile aFile : subFiles) { String currentFileName = aFile.getName(); if (currentFileName.equals(".") || currentFileName.equals("..")) { continue; } else { ftp.deleteFile(currentFileName); } } } ftp.changeToParentDirectory(); ftp.removeDirectory("acme-challenge"); ftp.changeToParentDirectory(); ftp.removeDirectory(".well-known"); ftp.logout(); } catch (IOException e) { throw new AcmeException(e); } finally { if (ftp.isConnected()) { try { ftp.disconnect(); } catch (IOException ioe) { } } } }
From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java
@Override public List<String> getDirectoryNames(final String dir) throws IOException { try {/*from ww w . j a va2 s . c o m*/ ftpClient.setFileType(FTP.ASCII_FILE_TYPE); final FTPFile[] files = ftpClient.listFiles(dir); if (files.length == 0) throw new NoSuchFileException(dir); if (files.length == 1) handleFailedDirectoryList(dir, files[0]); final List<String> ret = new ArrayList<>(files.length); String name; for (final FTPFile file : files) { name = file.getName(); if (!(".".equals(name) || "..".equals(name))) ret.add(name); } return ret; } catch (FTPConnectionClosedException e) { status = Status.DEAD; throw new IOException("service unavailable", e); } }
From source file:info.track_mate.util.DefaultFTPClient.java
/** {@inheritDoc} */ public Collection<FTPFile> listFiles() throws Exception { org.apache.commons.net.ftp.FTPFile[] ftpFiles = ftpClient.listFiles(); Collection<FTPFile> toReturn = new ArrayList<FTPFile>(); for (org.apache.commons.net.ftp.FTPFile ftpFile : ftpFiles) { toReturn.add(new DefaultFTPFile(ftpFile.getName(), ftpFile.getSize())); }// w ww .j a v a2 s . c om return toReturn; }