public void get()

in src/java/org/apache/ivy/plugins/repository/vsftp/VsftpRepository.java [150:226]


    public void get(final String source, File destination) throws IOException {
        initIvy();
        try {
            fireTransferInitiated(getResource(source), TransferEvent.REQUEST_GET);
            File destDir = destination.getParentFile();
            if (destDir != null) {
                sendCommand("lcd " + destDir.getAbsolutePath());
            }
            if (destination.exists()) {
                destination.delete();
            }

            int index = source.lastIndexOf('/');
            String srcName = (index == -1) ? source : source.substring(index + 1);
            final File to = (destDir == null) ? Checks.checkAbsolute(srcName, "source")
                    : new File(destDir, srcName);

            final IOException[] ex = new IOException[1];
            Thread get = new IvyThread() {
                public void run() {
                    initContext();
                    try {
                        sendCommand("get " + source, getExpectedDownloadMessage(source, to), 0);
                    } catch (IOException e) {
                        ex[0] = e;
                    }
                }
            };
            get.start();

            long prevLength = 0;
            long lastUpdate = System.currentTimeMillis();
            long timeout = readTimeout;
            while (get.isAlive()) {
                checkInterrupted();
                long length = to.exists() ? to.length() : 0;
                if (length > prevLength) {
                    fireTransferProgress(length - prevLength);
                    lastUpdate = System.currentTimeMillis();
                    prevLength = length;
                } else {
                    if (System.currentTimeMillis() - lastUpdate > timeout) {
                        Message.verbose("download hang for more than " + timeout
                                + "ms. Interrupting.");
                        get.interrupt();
                        if (to.exists()) {
                            to.delete();
                        }
                        throw new IOException(source + " download timeout from " + getHost());
                    }
                }
                try {
                    get.join(GET_JOIN_MAX_TIME);
                } catch (InterruptedException e) {
                    if (to.exists()) {
                        to.delete();
                    }
                    return;
                }
            }
            if (ex[0] != null) {
                if (to.exists()) {
                    to.delete();
                }
                throw ex[0];
            }

            to.renameTo(destination);
            fireTransferCompleted(destination.length());
        } catch (IOException ex) {
            fireTransferError(ex);
            cleanup(ex);
            throw ex;
        } finally {
            cleanup();
        }
    }