Example usage for org.apache.commons.net.ftp FTPFile isFile

List of usage examples for org.apache.commons.net.ftp FTPFile isFile

Introduction

In this page you can find the example usage for org.apache.commons.net.ftp FTPFile isFile.

Prototype

public boolean isFile() 

Source Link

Document

Determine if the file is a regular file.

Usage

From source file:patcher.FXMLDocumentController.java

private ArrayList<String> getMissing(FTPClient ftp, File[] filesList) throws IOException {
    ArrayList<String> missing = new ArrayList<>();
    FTPFile[] files = ftp.listFiles(folder);
    for (FTPFile file : files) {
        boolean found = false;
        for (File test : filesList) {
            if (test.getName().equals(file.getName())) {
                found = true;/*from  www  .j  a v  a 2s  .com*/
            }
        }
        if (found == false) {
            if (file.isFile()) {
                missing.add(file.getName());
            }

        }
    }
    return missing;
}

From source file:restGateWay.HTMLGenerator.java

/**
 * This method return HTML source code than provide user to browse files, or retrive one
 *
 * @param file list of Files//from   ww w  .j  a va 2s  .  c o  m
 * @return String containing HTML part containing href link 
 */
private String getLinkForFileName(String cwd, FTPFile file) {
    String tmp = "";
    if (file.isDirectory())
        tmp += "<img src=\"http://agingparentsauthority.com/wp-content/plugins/sem-theme-pro/icons/folder.png\" alt=\"[   ]\" />       <a href='"
                + path + "resources/file" + cwd + "/" + file.getName() + "'>" + file.getName() + "</a></br>\n";
    if (file.isFile()) {
        tmp += "<img src=\"http://www.appropedia.org/skins/vector/images/file-icon.png\" alt=\"[   ]\" /> "
                + "<a href=\"" + path + "/resources/file/" + cwd + "/delete/" + file.getName()
                + "\"><img src=\"http://www.domainedesnoms.com/themes/site/ddn.fr/images/picto/delete.png\" /></a> "
                + "<a href=\"" + path + "/resources/file/" + cwd + "/download/" + file.getName() + "\">"
                + file.getName() + "</a></br>";
    }
    return tmp;
}

From source file:s32a.CodebaseDeployer.java

/**
 * Uploads given files to ftp server.//from w w w  .ja  va2s .  co  m
 *
 * @param input key: desired name on server, Value: file to upload.
 */
private void uploadFiles(Map<String, File> input) {

    FTPClient client = null;
    if (SSL) {
        client = new FTPSClient(false);
    } else {
        client = new FTPClient();
    }
    FileInputStream fis = null;
    FileOutputStream fos = null;

    try {
        System.out.println("connecting");
        client.connect(ftpServer);
        boolean login = client.login(this.userName, this.password);
        System.out.println("login: " + login);
        client.enterLocalPassiveMode();

        //            client.setFileType(FTP.ASCII_FILE_TYPE);

        //Creates all directories required on the server
        System.out.println("creating directories");
        client.makeDirectory("Airhockey");
        client.makeDirectory("Airhockey/Codebase");
        client.makeDirectory("Airhockey/Servers");
        client.makeDirectory("Airhockey/Codebase/s32a");
        System.out.println("default directories made");
        for (String s : directories) {
            client.makeDirectory(s);
        }

        //Uploads codebase URL
        fis = new FileInputStream(this.codebaseFile);
        boolean stored = client.storeFile("Airhockey/Codebase/codebase.properties", fis);
        //            client.completePendingCommand();
        System.out.println("Stored codebase file: " + stored);
        fis.close();

        // Removes references to all servers
        for (FTPFile f : client.listFiles("Airhockey/Servers")) {
            if (f.isFile()) {
                System.out.println("Deleting Server Listing: " + f.getName());
                client.deleteFile("/Airhockey/Servers/" + f.getName());
            }
        }

        // Uploads all class files
        System.out.println("Uploading classes");
        String defaultLoc = fs + "Airhockey" + fs + "Codebase" + fs;
        for (String dest : input.keySet()) {
            fis = new FileInputStream(input.get(dest));
            if (!client.storeFile(defaultLoc + dest, fis)) {
                System.out.println("unable to save: " + defaultLoc + dest);
            }
            fis.close();
            //                client.completePendingCommand();
        }

        client.logout();
    } catch (IOException ex) {
        System.out.println("IOException: " + ex.getMessage());
        ex.printStackTrace();
    } catch (Exception ex) {
        System.out.println("exception caught: " + ex.getMessage());
    } finally {
        try {
            if (fis != null) {
                fis.close();
            }
            if (fos != null) {
                fos.close();
            }
            client.disconnect();
            System.exit(0);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

From source file:savant.agp.HTTPBrowser.java

/**
 * Get a nicely formatted string describing the file's size.
 * /*from  w  ww  .j  a v a  2  s.  c om*/
 * @param f the FTP entry whose size we're displaying
 * @return a string describing the size, or null if f is a directory
 */
private static String getSizeString(FTPFile f) {
    if (f != null && f.isFile()) {
        long size = f.getSize();
        if (size < 1E6) {
            return String.format("%.2f kB", size / 1.0E3);
        } else if (size < 1E9) {
            return String.format("%.2f MB", size / 1.0E6);
        } else {
            return String.format("%.2f GB", size / 1.0E9);
        }
    }
    return null;
}

From source file:us.mn.state.dot.tms.client.camera.FTPStream.java

/** Create a new JPEG stream 
 * @throws IOException *///  w  w  w. jav  a2  s .  c o m
public FTPStream(Scheduler s, VideoRequest req, Camera c) throws IOException {
    size = UI.dimension(req.getSize().width, req.getSize().height);
    ftpClient = new FTPClient();

    /** Get ip and port from encoder field */
    baseUrl = c.getEncoder();
    String[] params = baseUrl.split(":");
    ip = params[0];

    /** Default port is 80 if no port is provided */
    if (params.length > 1) {
        port = Integer.parseInt(params[1]);
    } else {
        port = 80;
    }

    /** Get base directory of images, provide root (/) if null or blank */
    ftpPath = c.getFtpPath();
    if (ftpPath == null || ftpPath.trim().equals("")) {
        ftpPath = "/";
    }

    /** Get filename if static image path */
    same_filename = c.getSameFilename();
    if (same_filename) {
        ftp_filename = c.getFtpFilename();
    }

    /** Use anonymous with blank password if username field is left blank */
    ftpUsername = c.getFtpUsername();
    ftpPassword = c.getFtpPassword();
    if (ftpUsername == null || ftpUsername.trim().equals("")) {
        ftpUsername = "anonomymous";
        ftpPassword = "";
    }

    ftpFilter = new FTPFileFilter() {
        @Override
        public boolean accept(FTPFile ftpFile) {
            return (ftpFile.isFile()
                    && (ftpFile.getName().endsWith(".jpg") || ftpFile.getName().endsWith(".png")));
        }
    };

    /** Get the FTP Image */
    getFtpImage();

    /** Create thread to read image based on refresh interval */
    /** @throws IOException */
    final Job job = new Job(Calendar.MINUTE, c.getRefInterval()) {
        public void perform() throws IOException {
            if (running) {
                getFtpImage();
            }
        }

        public boolean isRepeating() {
            return running;
        }
    };
    s.addJob(job);

}