Package htsjdk.samtools.util.ftp

Examples of htsjdk.samtools.util.ftp.FTPClient


        }
        // NOTE-- DO NOT TRY TO CLOSE STREAM.  IT WILL HANG.
    }

    public static long getContentLength(URL url) throws IOException {
        FTPClient ftp = null;
        try {
            ftp = FTPUtils.connect(url.getHost(), url.getUserInfo(), null);
            String sizeString = ftp.executeCommand("size " + url.getPath()).getReplyString();
            return Integer.parseInt(sizeString);
        } catch (Exception e) {
            return -1 ;
        }
        finally {
            if(ftp != null) {
                ftp.disconnect();
            }
        }

    }
View Full Code Here


     * @return
     * @throws IOException
     */
    public static synchronized FTPClient connect(String host, String userInfo, UserPasswordInput userPasswordInput) throws IOException {

        FTPClient ftp = new FTPClient();
        FTPReply reply = ftp.connect(host);
        if (!reply.isSuccess()) {
            throw new RuntimeException("Could not connect to " + host);
        }

        String user = "anonymous";
        String password = "igv@broadinstitute.org";

        if (userInfo == null) {
            userInfo = userCredentials.get(host);
        }
        if (userInfo != null) {
            String[] tmp = userInfo.split(":");
            user = tmp[0];
            if (tmp.length > 1) {
                password = tmp[1];
            }
        }

        reply = ftp.login(user, password);
        if (!reply.isSuccess()) {
            if (userPasswordInput == null) {
                throw new RuntimeException("Login failure for host: " + host);
            } else {
                userPasswordInput.setHost(host);
                boolean success = false;
                while (!success) {
                    if (userPasswordInput.showDialog()) {
                        user = userPasswordInput.getUser();
                        password = userPasswordInput.getPassword();
                        reply = ftp.login(user, password);
                        success = reply.isSuccess();
                    } else {
                        // canceled
                        break;
                    }

                }
                if (success) {
                    userInfo = user + ":" + password;
                    userCredentials.put(host, userInfo);
                } else {
                    throw new RuntimeException("Login failure for host: " + host);
                }
            }
        }

        reply = ftp.binary();
        if (!(reply.isSuccess())) {
            throw new RuntimeException("Could not set binary mode on host: " + host);
        }

        return ftp;
View Full Code Here

    static byte[] expectedBytes = "abcdefghijklmnopqrstuvwxyz\n".getBytes();
    FTPClient client;

    @Before
    public void setUp() throws IOException {
        client = new FTPClient();
        FTPReply reply = client.connect(host);
        assertTrue(reply.isSuccess());
    }
View Full Code Here

        log.debug("Opening connection stream to  " + url);
        if (url.getProtocol().toLowerCase().equals("ftp")) {
            String userInfo = url.getUserInfo();
            String host = url.getHost();
            String file = url.getPath();
            FTPClient ftp = FTPUtils.connect(host, userInfo, new UserPasswordInputImpl());
            ftp.pasv();
            ftp.retr(file);
            return new FTPStream(ftp);

        } else {
            return openConnectionStream(url, null);
        }
View Full Code Here

            String resp = null;
            try {
                URL url = new URL(path);
                if (path.startsWith("ftp:")) {
                    String host = url.getHost();
                    FTPClient ftp = FTPUtils.connect(host, url.getUserInfo(), new UserPasswordInputImpl());
                    ftp.pasv();
                    FTPReply reply = ftp.executeCommand("MDTM " + url.getPath());
                    resp = reply.getReplyString();
                    return ftpDateFormat.parse(resp).getTime();
                } else {
                    return HttpUtils.getInstance().getLastModified(url);
                }
View Full Code Here

TOP

Related Classes of htsjdk.samtools.util.ftp.FTPClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.