Search in sources :

Example 1 with DownloadFilterOptions

use of ch.cyberduck.core.transfer.download.DownloadFilterOptions in project cyberduck by iterate-ch.

the class TerminalTransferFactory method create.

public Transfer create(final CommandLine input, final Host host, final Path remote, final List<TransferItem> items) throws BackgroundException {
    final Transfer transfer;
    final TerminalAction type = TerminalActionFinder.get(input);
    if (null == type) {
        throw new BackgroundException(LocaleFactory.localizedString("Unknown"), "Unknown transfer type");
    }
    switch(type) {
        case download:
            if (StringUtils.containsAny(remote.getName(), '*')) {
                transfer = new DownloadTransfer(host, items, new DownloadGlobFilter(remote.getName()));
            } else {
                transfer = new DownloadTransfer(host, items);
            }
            if (input.hasOption(TerminalOptionsBuilder.Params.nochecksum.name())) {
                final DownloadFilterOptions options = new DownloadFilterOptions(host);
                options.checksum = Boolean.parseBoolean(input.getOptionValue(TerminalOptionsBuilder.Params.nochecksum.name()));
                ((DownloadTransfer) transfer).withOptions(options);
            }
            break;
        case upload:
            transfer = new UploadTransfer(host, items);
            if (input.hasOption(TerminalOptionsBuilder.Params.nochecksum.name())) {
                final UploadFilterOptions options = new UploadFilterOptions(host);
                options.checksum = Boolean.parseBoolean(input.getOptionValue(TerminalOptionsBuilder.Params.nochecksum.name()));
                ((UploadTransfer) transfer).withOptions(options);
            }
            break;
        case synchronize:
            transfer = new SyncTransfer(host, items.iterator().next());
            break;
        default:
            throw new BackgroundException(LocaleFactory.localizedString("Unknown"), String.format("Unknown transfer type %s", type.name()));
    }
    if (input.hasOption(TerminalOptionsBuilder.Params.throttle.name())) {
        try {
            transfer.setBandwidth(Float.parseFloat(input.getOptionValue(TerminalOptionsBuilder.Params.throttle.name())));
        } catch (NumberFormatException ignore) {
        // 
        }
    }
    return transfer;
}
Also used : DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) SyncTransfer(ch.cyberduck.core.transfer.SyncTransfer) DownloadFilterOptions(ch.cyberduck.core.transfer.download.DownloadFilterOptions) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) UploadFilterOptions(ch.cyberduck.core.transfer.upload.UploadFilterOptions) BackgroundException(ch.cyberduck.core.exception.BackgroundException) SyncTransfer(ch.cyberduck.core.transfer.SyncTransfer)

Example 2 with DownloadFilterOptions

use of ch.cyberduck.core.transfer.download.DownloadFilterOptions in project cyberduck by iterate-ch.

the class DownloadTransferTest method testPrepareDownloadResumeFilter.

@Test
public void testPrepareDownloadResumeFilter() throws Exception {
    final Host host = new Host(new TestProtocol());
    final Session<?> session = new NullTransferSession(host);
    final Path test = new Path("/transfer/test", EnumSet.of(Path.Type.file));
    test.attributes().setSize(5L);
    final Local local = new Local(System.getProperty("java.io.tmpdir") + "/transfer/" + UUID.randomUUID().toString());
    LocalTouchFactory.get().touch(local);
    final OutputStream out = local.getOutputStream(false);
    IOUtils.write("test", out, Charset.defaultCharset());
    out.close();
    final Transfer transfer = new DownloadTransfer(host, test, local) {

        @Override
        public AbstractDownloadFilter filter(final Session<?> source, final Session<?> d, final TransferAction action, final ProgressListener listener) {
            return new ResumeFilter(new DownloadSymlinkResolver(Collections.singletonList(new TransferItem(test))), new NullTransferSession(new Host(new TestProtocol())), new DownloadFilterOptions(host), new DefaultDownloadFeature(source.getFeature(Read.class)) {

                @Override
                public boolean offset(final Path file) {
                    return true;
                }
            });
        }
    };
    final SingleTransferWorker worker = new SingleTransferWorker(session, null, transfer, new TransferOptions(), new TransferSpeedometer(transfer), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            fail();
            return null;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService());
    worker.prepare(test, local, new TransferStatus().exists(true), TransferAction.resume);
    final TransferStatus status = new TransferStatus();
    status.setExists(true);
    final TransferStatus expected = new TransferStatus();
    expected.setAppend(true);
    expected.setExists(true);
    expected.setOffset("test".getBytes().length);
    // Transfer length
    expected.setLength(5L - "test".getBytes().length);
    assertEquals(expected, worker.getStatus().get(new TransferItem(test, local)));
    local.delete();
}
Also used : OutputStream(java.io.OutputStream) SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DownloadFilterOptions(ch.cyberduck.core.transfer.download.DownloadFilterOptions) ResumeFilter(ch.cyberduck.core.transfer.download.ResumeFilter) DownloadSymlinkResolver(ch.cyberduck.core.transfer.symlink.DownloadSymlinkResolver) DefaultDownloadFeature(ch.cyberduck.core.shared.DefaultDownloadFeature) Test(org.junit.Test)

Example 3 with DownloadFilterOptions

use of ch.cyberduck.core.transfer.download.DownloadFilterOptions in project cyberduck by iterate-ch.

the class BrowserTableDataSource method namesOfPromisedFilesDroppedAtDestination.

/**
 * @return the names (not full paths) of the files that the receiver promises to create at dropDestination. This
 * method is invoked when the drop has been accepted by the destination and the destination, in the case of another
 * Cocoa application, invokes the NSDraggingInfo method namesOfPromisedFilesDroppedAtDestination. For long
 * operations, you can cache dropDestination and defer the creation of the files until the finishedDraggingImage
 * method to avoid blocking the destination application.
 */
@Override
public NSArray namesOfPromisedFilesDroppedAtDestination(final NSURL url) {
    if (log.isDebugEnabled()) {
        log.debug(String.format("Return names of promised files dropped at %s", url));
    }
    NSMutableArray promisedDragNames = NSMutableArray.array();
    if (null != url) {
        final Local destination = LocalFactory.get(url.path());
        final DownloadFilterOptions options = new DownloadFilterOptions(controller.getSession().getHost());
        if (destination.isChild(new TemporarySupportDirectoryFinder().find())) {
            options.icon = false;
            options.segments = false;
        }
        final PathPasteboard pasteboard = controller.getPasteboard();
        final List<TransferItem> downloads = new ArrayList<TransferItem>();
        for (Path p : pasteboard) {
            downloads.add(new TransferItem(p, LocalFactory.get(destination, p.getName())));
            // Add to returned path names
            promisedDragNames.addObject(p.getName());
        }
        if (downloads.size() == 1) {
            if (downloads.iterator().next().remote.isFile()) {
                final Local file = downloads.iterator().next().local;
                if (!file.exists()) {
                    try {
                        LocalTouchFactory.get().touch(file);
                        if (options.icon) {
                            IconServiceFactory.get().set(file, new TransferStatus().withLength(0L));
                        }
                    } catch (AccessDeniedException e) {
                        log.warn(String.format("Failure creating file %s %s", file, e.getMessage()));
                    }
                }
            }
            if (downloads.iterator().next().remote.isDirectory()) {
                final Local file = downloads.iterator().next().local;
                if (!file.exists()) {
                    try {
                        new DefaultLocalDirectoryFeature().mkdir(file);
                    } catch (AccessDeniedException e) {
                        log.warn(e.getMessage());
                    }
                }
            }
        }
        // kTemporaryFolderType
        final boolean dock = destination.equals(LocalFactory.get("~/Library/Caches/TemporaryItems"));
        if (dock) {
            for (Path p : pasteboard) {
                // Drag to application icon in dock.
                controller.edit(p);
            }
        } else {
            final Transfer transfer = new DownloadTransfer(controller.getSession().getHost(), downloads).withOptions(options);
            controller.transfer(transfer, Collections.emptyList());
        }
        pasteboard.clear();
    }
    // Filenames
    return promisedDragNames;
}
Also used : Path(ch.cyberduck.core.Path) AccessDeniedException(ch.cyberduck.core.exception.AccessDeniedException) DownloadFilterOptions(ch.cyberduck.core.transfer.download.DownloadFilterOptions) ArrayList(java.util.ArrayList) Local(ch.cyberduck.core.Local) PathPasteboard(ch.cyberduck.core.pasteboard.PathPasteboard) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) NSMutableArray(ch.cyberduck.binding.foundation.NSMutableArray) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) CopyTransfer(ch.cyberduck.core.transfer.CopyTransfer) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) DownloadTransfer(ch.cyberduck.core.transfer.DownloadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) TransferItem(ch.cyberduck.core.transfer.TransferItem) TemporarySupportDirectoryFinder(ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder)

Aggregations

DownloadFilterOptions (ch.cyberduck.core.transfer.download.DownloadFilterOptions)3 DownloadTransfer (ch.cyberduck.core.transfer.DownloadTransfer)2 Transfer (ch.cyberduck.core.transfer.Transfer)2 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)2 NSMutableArray (ch.cyberduck.binding.foundation.NSMutableArray)1 Local (ch.cyberduck.core.Local)1 Path (ch.cyberduck.core.Path)1 AccessDeniedException (ch.cyberduck.core.exception.AccessDeniedException)1 BackgroundException (ch.cyberduck.core.exception.BackgroundException)1 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)1 DefaultLocalDirectoryFeature (ch.cyberduck.core.local.DefaultLocalDirectoryFeature)1 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)1 PathPasteboard (ch.cyberduck.core.pasteboard.PathPasteboard)1 TemporarySupportDirectoryFinder (ch.cyberduck.core.preferences.TemporarySupportDirectoryFinder)1 DefaultDownloadFeature (ch.cyberduck.core.shared.DefaultDownloadFeature)1 CopyTransfer (ch.cyberduck.core.transfer.CopyTransfer)1 SyncTransfer (ch.cyberduck.core.transfer.SyncTransfer)1 TransferItem (ch.cyberduck.core.transfer.TransferItem)1 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)1 ResumeFilter (ch.cyberduck.core.transfer.download.ResumeFilter)1