List of usage examples for org.apache.commons.net.ftp FTPFile getName
public String getName()
From source file:com.microsoft.azuretools.utils.WebAppUtils.java
public static boolean doesRemoteFolderExist(FTPClient ftp, String path, String folderName) throws IOException { FTPFile[] files = ftp.listFiles(path); for (FTPFile file : files) { if (file.isDirectory() && file.getName().equalsIgnoreCase(folderName)) { return true; }//from w w w . ja va 2 s . com } return false; }
From source file:de.ipk_gatersleben.ag_nw.graffiti.services.GUIhelper.java
private static ArrayList<String> listFiles(final BackgroundTaskStatusProviderSupportingExternalCall status, String downloadURL, String server, String remotePath, final FTPClient ftp) { String username;//from w w w . j a v a 2 s. c o m String password; username = "anonymous@" + server; password = "anonymous"; final ObjectRef myoutputstream = new ObjectRef(); ftp.addProtocolCommandListener(new ProtocolCommandListener() { public void protocolCommandSent(ProtocolCommandEvent arg0) { status.setCurrentStatusText1("Command: " + arg0.getMessage()); } public void protocolReplyReceived(ProtocolCommandEvent arg0) { status.setCurrentStatusText2("Message: " + arg0.getMessage()); if (myoutputstream.getObject() != null) { String msg = arg0.getMessage(); if (msg.indexOf("Opening BINARY mode") >= 0) { if (msg.indexOf("(") > 0) { msg = msg.substring(msg.indexOf("(") + "(".length()); if (msg.indexOf(" ") > 0) { msg = msg.substring(0, msg.indexOf(" ")); try { long max = Long.parseLong(msg); MyOutputStream os = (MyOutputStream) myoutputstream.getObject(); os.setMaxBytes(max); } catch (Exception e) { System.out.println( "Could not determine file length for detailed progress information"); } } } } } } }); System.out.println("FTP LIST DIRECTORY: " + downloadURL); try { if (ftp.isConnected()) { status.setCurrentStatusText2("Using open FTP connection"); System.out.println("Reusing open FTP connection"); } else { ftp.connect(server); int reply = ftp.getReplyCode(); if (!FTPReply.isPositiveCompletion(reply)) { ftp.disconnect(); status.setCurrentStatusText1("Can't connect to FTP server"); status.setCurrentStatusText2("ERROR"); return new ArrayList<String>(); } if (!ftp.login("anonymous", "anonymous")) { if (!ftp.login(username, password)) { ftp.disconnect(); status.setCurrentStatusText1("Can't login to FTP server"); status.setCurrentStatusText2("ERROR"); return new ArrayList<String>(); } } status.setCurrentStatusText1("Set Binary Transfer Mode"); ftp.setFileType(FTP.BINARY_FILE_TYPE); status.setCurrentStatusText2("Activate Passive Transfer Mode"); ftp.enterLocalPassiveMode(); } status.setCurrentStatusText1("Start download..."); status.setCurrentStatusText2("Please Wait."); ftp.setRemoteVerificationEnabled(false); FTPFile[] res = ftp.listFiles(remotePath); ArrayList<String> result = new ArrayList<String>(); for (FTPFile r : res) { result.add(r.getName()); } return result; } catch (Exception err) { ErrorMsg.addErrorMessage(err); if (ftp != null && ftp.isConnected()) { try { System.out.println("Disconnect FTP connection (following error condition)"); ftp.disconnect(); } catch (Exception err2) { ErrorMsg.addErrorMessage(err2); } } return new ArrayList<String>(); } }
From source file:com.microsoft.azuretools.utils.WebAppUtils.java
public static void removeFtpDirectory(FTPClient ftpClient, String path, IProgressIndicator pi) throws IOException { String prefix = "Removing from FTP server: "; FTPFile[] subFiles = ftpClient.listFiles(path); if (subFiles.length > 0) { for (FTPFile ftpFile : subFiles) { if (pi != null && pi.isCanceled()) break; String currentFileName = ftpFile.getName(); if (currentFileName.equals(".") || currentFileName.equals("..")) { continue; // skip }// www .j a v a 2s .c o m String path1 = path + "/" + currentFileName; if (ftpFile.isDirectory()) { // remove the sub directory removeFtpDirectory(ftpClient, path1, pi); } else { // delete the file if (pi != null) pi.setText2(prefix + path1); ftpClient.deleteFile(path1); } } } if (pi != null) pi.setText2(prefix + path); ftpClient.removeDirectory(path); if (pi != null) pi.setText2(""); }
From source file:fr.acxio.tools.agia.ftp.RegexFilenameFilter.java
@Override public boolean accept(FTPFile sFile) { return pattern.matcher(sFile.getName()).matches(); }
From source file:de.ep3.ftpc.model.CrawlerDirectory.java
@Override public boolean accept(FTPFile file) { if (file.getName().equals(".") || file.getName().equals("..")) { return false; } else {//from ww w . ja v a 2 s .co m return true; } }
From source file:de.idos.updates.lookup.FtpLookup.java
private Version findLatestVersion() throws IOException { FTPClient ftpClient = new FTPClient(); ftpClient.connect(inetAddress);//from ww w . j a v a2s . c o m ftpClient.enterLocalPassiveMode(); if (login != null) { ftpClient.login(login, null); } if (workingDir != null) { ftpClient.changeWorkingDirectory(workingDir); } FTPFile[] availableVersionsDirs = ftpClient.listDirectories(); List<String> strings = new ArrayList<String>(); for (FTPFile ftpFile : availableVersionsDirs) { strings.add(ftpFile.getName()); } List<Version> versions = new VersionFactory().createVersionsFromStrings(strings); return new VersionFinder().findLatestVersion(versions); }
From source file:dhz.skz.citaci.weblogger.WlFileFilter.java
@Override public boolean accept(FTPFile file) { if (file.isDirectory()) return false; String strL = file.getName().toLowerCase(); String ptStr = "^(" + nazivPostaje + ")-(\\d{8})(.?)\\.csv"; Pattern pt = Pattern.compile(ptStr); Matcher m = pt.matcher(strL); if (m.matches()) { try {/*w w w .j a va2 s . c om*/ Date sada = formatter.parse(m.group(2)); if (zadnji.getTime() - sada.getTime() < 24 * 3600 * 1000) { return true; } } catch (ParseException ex) { log.log(Level.SEVERE, null, ex); } } return false; }
From source file:dhz.skz.citaci.weblogger.zerospan.WlZeroSpanFileFilter.java
@Override public boolean accept(FTPFile file) { if (file.isDirectory()) return false; String strL = file.getName().toLowerCase(); String ptStr = "^(" + nazivPostaje + ")_c-(\\d{8})\\.csv"; Pattern pt = Pattern.compile(ptStr); Matcher m = pt.matcher(strL); if (m.matches()) { try {//from w ww .j a v a 2 s .c o m Date sada = formatter.parse(m.group(2)); if (zadnji.getTime() - sada.getTime() < 24 * 3600 * 1000) { return true; } } catch (ParseException ex) { log.log(Level.SEVERE, null, ex); } } return false; }
From source file:com.nononsenseapps.filepicker.sample.ftp.FTPPath.java
public FTPPath(@NonNull FTPPath mCurrentPath, @NonNull FTPFile file) { this.file = file; if (mCurrentPath.path.endsWith("/")) { this.path = mCurrentPath + file.getName(); } else {/*from www . j a va 2 s . c om*/ this.path = mCurrentPath.path + "/" + file.getName(); } }
From source file:m09_uf3_7.ClientFTP.java
public List<String> listar() throws IOException { List<String> lista = new ArrayList<>(); // creamos una array List if (this.login) { // si es true // --CODE-- String lista2 = ftp.printWorkingDirectory(); FTPFile[] listars = ftp.listFiles(lista2); for (FTPFile file : listars) { String details = file.getName(); System.out.println(details); }/*w ww . ja va 2 s . c o m*/ } else { System.out.println("No logeat..."); } return lista; }