Package htsjdk.samtools.util.ftp

Examples of htsjdk.samtools.util.ftp.FTPReply


     * @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


    FTPClient client;

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

    }


    @Test
    public void testLogin() throws Exception {
        FTPReply reply = client.login("anonymous", "igv@broadinstitute.org");
        assertTrue(reply.isSuccess());

    }
View Full Code Here

    @Test
    public void testPasv() throws Exception {

        try {
            FTPReply reply = client.login("anonymous", "igv@broadinstitute.org");
            assertTrue(reply.isSuccess());

            reply = client.pasv();
            assertTrue(reply.isSuccess());
        }

        finally {
            client.closeDataStream();
        }
View Full Code Here

    }

    @Test
    public void testDownload() throws Exception {
        try {
            FTPReply reply = client.login("anonymous", "igv@broadinstitute.org");
            assertTrue(reply.isSuccess());

            reply = client.binary();
            assertTrue(reply.isSuccess());

            reply = client.pasv();
            assertTrue(reply.isSuccess());

            reply = client.retr(file);
            assertTrue(reply.getCode() == 150);

            InputStream is = client.getDataStream();
            int idx = 0;
            int b;
            while ((b = is.read()) >= 0) {
                assertEquals(expectedBytes[idx], (byte) b);
                idx++;
            }

        }

        finally {
            client.closeDataStream();
            FTPReply reply = client.retr(file);
            System.out.println(reply.getCode());
            assertTrue(reply.isSuccess());

        }
    }
View Full Code Here

    }

    @Test
    public void testRest() throws Exception {
        try {
            FTPReply reply = client.login("anonymous", "igv@broadinstitute.org");
            assertTrue(reply.isSuccess());

            reply = client.binary();
            assertTrue(reply.isSuccess());

            reply = client.pasv();
            assertTrue(reply.isSuccess());

            final int restPosition = 5;
            client.setRestPosition(restPosition);

            reply = client.retr(file);
            assertTrue(reply.getCode() == 150);

            InputStream is = client.getDataStream();
            int idx = restPosition;
            int b;
            while ((b = is.read()) >= 0) {
                assertEquals(expectedBytes[idx], (byte) b);
                idx++;
            }

        }

        finally {
            client.closeDataStream();
            FTPReply reply = client.retr(file);
            System.out.println(reply.getCode());
            assertTrue(reply.isSuccess());

        }
    }
View Full Code Here

    @Test
    public void testMultiplePasv() throws Exception {

        try {
            FTPReply reply = client.login("anonymous", "igv@broadinstitute.org");
            assertTrue(reply.isSuccess());

            reply = client.pasv();
            assertTrue(reply.isSuccess());
            client.closeDataStream();

            reply = client.pasv();
            assertTrue(reply.isSuccess());
            client.closeDataStream();


        }
View Full Code Here

    }


    @Test
    public void testMultipleRest() throws Exception {
        FTPReply reply = client.login("anonymous", "igv@broadinstitute.org");
        assertTrue(reply.isSuccess());

        reply = client.binary();
        assertTrue(reply.isSuccess());

        restRetr(5, 10);
        restRetr(2, 10);
        restRetr(15, 10);
View Full Code Here

    private void restRetr(int restPosition, int length) throws IOException {

        try {

            if (client.getDataStream() == null) {
                FTPReply reply = client.pasv();
                assertTrue(reply.isSuccess());
            }

            client.setRestPosition(restPosition);

            FTPReply reply = client.retr(file);
            //assertTrue(reply.getCode() == 150);

            InputStream is = client.getDataStream();

            byte[] buffer = new byte[length];
            is.read(buffer);


            for (int i = 0; i < length; i++) {
                System.out.print((char) buffer[i]);
                assertEquals(expectedBytes[i + restPosition], buffer[i]);
            }
            System.out.println();
        }

        finally {
            client.closeDataStream();
            FTPReply reply = client.getReply()// <== MUST READ THE REPLY
            System.out.println(reply.getReplyString());


        }
    }
View Full Code Here

        return this.length;
    }

    private long getLength(){
        try {
            FTPReply reply = ftp.size(path);
            if (reply.isSuccess()) {
                return Long.parseLong(reply.getReplyString());
            }
        } catch (IOException e) {
            log.error("Error getting length. " + e.getMessage(), e);
        }
        return -1;
View Full Code Here

TOP

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

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.