Search in sources :

Example 1 with UploadFilterOptions

use of ch.cyberduck.core.transfer.upload.UploadFilterOptions 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 UploadFilterOptions

use of ch.cyberduck.core.transfer.upload.UploadFilterOptions in project cyberduck by iterate-ch.

the class OverwriteFilterTest method testComplete.

@Test
public void testComplete() throws Exception {
    final HashMap<Path, Path> files = new HashMap<Path, Path>();
    final Path source = new Path("a", EnumSet.of(Path.Type.file));
    source.attributes().setSize(1L);
    source.attributes().setPermission(new Permission(777));
    final Long time = System.currentTimeMillis();
    source.attributes().setModificationDate(time);
    final boolean[] timestampWrite = new boolean[1];
    final boolean[] permissionWrite = new boolean[1];
    final Path target = new Path("a", EnumSet.of(Path.Type.file));
    files.put(source, target);
    final Host host = new Host(new TestProtocol());
    OverwriteFilter f = new OverwriteFilter(new NullTransferSession(host), new NullSession(host) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type.equals(Timestamp.class)) {
                return (T) new DefaultTimestampFeature() {

                    @Override
                    public void setTimestamp(final Path file, final TransferStatus status) {
                        assertEquals(time, status.getTimestamp());
                        timestampWrite[0] = true;
                    }
                };
            }
            if (type.equals(UnixPermission.class)) {
                return (T) new DefaultUnixPermissionFeature() {

                    @Override
                    public void setUnixOwner(final Path file, final String owner) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public void setUnixGroup(final Path file, final String group) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public Permission getUnixPermission(final Path file) {
                        throw new UnsupportedOperationException();
                    }

                    @Override
                    public void setUnixPermission(final Path file, final Permission permission) {
                        assertEquals(new Permission(777), permission);
                        permissionWrite[0] = true;
                    }
                };
            }
            return super._getFeature(type);
        }
    }, files, new UploadFilterOptions(host).withPermission(true).withTimestamp(true));
    final TransferStatus status = f.prepare(source, null, new TransferStatus(), new DisabledProgressListener());
    f.complete(source, null, new TransferOptions(), status, new DisabledProgressListener());
    assertFalse(permissionWrite[0]);
    assertFalse(timestampWrite[0]);
    status.setComplete();
    f.complete(source, null, new TransferOptions(), status, new DisabledProgressListener());
    assertTrue(permissionWrite[0]);
    assertTrue(timestampWrite[0]);
}
Also used : TestProtocol(ch.cyberduck.core.TestProtocol) HashMap(java.util.HashMap) NullSession(ch.cyberduck.core.NullSession) Timestamp(ch.cyberduck.core.features.Timestamp) NullTransferSession(ch.cyberduck.core.NullTransferSession) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) DefaultTimestampFeature(ch.cyberduck.core.shared.DefaultTimestampFeature) UnixPermission(ch.cyberduck.core.features.UnixPermission) Permission(ch.cyberduck.core.Permission) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Path(ch.cyberduck.core.Path) DisabledProgressListener(ch.cyberduck.core.DisabledProgressListener) UploadFilterOptions(ch.cyberduck.core.transfer.upload.UploadFilterOptions) Host(ch.cyberduck.core.Host) UnixPermission(ch.cyberduck.core.features.UnixPermission) DefaultUnixPermissionFeature(ch.cyberduck.core.shared.DefaultUnixPermissionFeature) Test(org.junit.Test)

Example 3 with UploadFilterOptions

use of ch.cyberduck.core.transfer.upload.UploadFilterOptions in project cyberduck by iterate-ch.

the class UploadTransferTest method testUploadTemporaryName.

@Test
public void testUploadTemporaryName() throws Exception {
    final Path test = new Path("/f", EnumSet.of(Path.Type.file));
    final AtomicBoolean moved = new AtomicBoolean();
    final Host host = new Host(new TestProtocol());
    final Session session = new NullSession(host) {

        @Override
        @SuppressWarnings("unchecked")
        public <T> T _getFeature(final Class<T> type) {
            if (type.equals(Find.class)) {
                return (T) new Find() {

                    @Override
                    public boolean find(final Path f, final ListProgressListener listener) {
                        return true;
                    }
                };
            }
            if (type.equals(Move.class)) {
                return (T) new Move() {

                    @Override
                    public Path move(final Path file, final Path renamed, final TransferStatus status, final Delete.Callback callback, final ConnectionCallback connectionCallback) {
                        assertEquals(test, renamed);
                        moved.set(true);
                        return renamed;
                    }

                    @Override
                    public boolean isRecursive(final Path source, final Path target) {
                        return true;
                    }

                    @Override
                    public boolean isSupported(final Path source, final Path target) {
                        return true;
                    }
                };
            }
            if (type.equals(AttributesFinder.class)) {
                return (T) new AttributesFinder() {

                    @Override
                    public PathAttributes find(final Path file, final ListProgressListener listener) {
                        return new PathAttributes();
                    }
                };
            }
            if (type.equals(Write.class)) {
                return (T) new Write() {

                    @Override
                    public StatusOutputStream write(final Path file, final TransferStatus status, final ConnectionCallback callback) {
                        fail();
                        return null;
                    }

                    @Override
                    public Append append(final Path file, final TransferStatus status) {
                        fail();
                        return new Write.Append(false);
                    }
                };
            }
            return super._getFeature(type);
        }
    };
    final AtomicBoolean set = new AtomicBoolean();
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    LocalTouchFactory.get().touch(local);
    final Transfer transfer = new UploadTransfer(host, test, local) {

        @Override
        public void transfer(final Session<?> source, final Session<?> destination, final Path file, Local local, final TransferOptions options, final TransferStatus overall, final TransferStatus segment, final ConnectionCallback connectionCallback, final ProgressListener listener, final StreamListener streamListener) {
            segment.setComplete();
            set.set(true);
        }

        @Override
        public AbstractUploadFilter filter(final Session<?> source, final Session<?> destination, final TransferAction action, final ProgressListener listener) {
            return super.filter(source, destination, action, listener).withOptions(new UploadFilterOptions(host).withTemporary(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()) {

        @Override
        public Future<TransferStatus> transfer(final TransferItem item, final TransferAction action) throws BackgroundException {
            return super.transfer(item, action);
        }
    };
    worker.prepare(test, local, new TransferStatus().exists(true), TransferAction.overwrite);
    assertNotNull(worker.getStatus().get(new TransferItem(test, local)));
    assertNotNull(worker.getStatus().get(new TransferItem(test, local)).getRename());
    worker.transfer(new TransferItem(test, local), TransferAction.overwrite);
    assertTrue(set.get());
    assertTrue(moved.get());
}
Also used : Delete(ch.cyberduck.core.features.Delete) Write(ch.cyberduck.core.features.Write) AttributesFinder(ch.cyberduck.core.features.AttributesFinder) SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) Move(ch.cyberduck.core.features.Move) StreamListener(ch.cyberduck.core.io.StreamListener) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) StatusOutputStream(ch.cyberduck.core.io.StatusOutputStream) UploadFilterOptions(ch.cyberduck.core.transfer.upload.UploadFilterOptions) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Find(ch.cyberduck.core.features.Find) Test(org.junit.Test)

Example 4 with UploadFilterOptions

use of ch.cyberduck.core.transfer.upload.UploadFilterOptions in project cyberduck by iterate-ch.

the class CryptoSFTPSingleTransferWorkerTest method testUpload.

@Test
public void testUpload() throws Exception {
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    StringBuilder directoryname = new StringBuilder();
    for (int i = 0; i < 10; i++) {
        directoryname.append(new AlphanumericRandomStringService().random());
    }
    final Path dir1 = new Path(vault, directoryname.toString(), EnumSet.of(Path.Type.directory));
    final Local localDirectory1 = new Local(System.getProperty("java.io.tmpdir"), directoryname.toString());
    new DefaultLocalDirectoryFeature().mkdir(localDirectory1);
    final byte[] content = RandomUtils.nextBytes(62768);
    final Path file1 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local localFile1 = new Local(localDirectory1, file1.getName());
    final OutputStream out1 = localFile1.getOutputStream(false);
    IOUtils.write(content, out1);
    out1.close();
    localFile1.attributes().setModificationDate(1513092263154L);
    final Path file2 = new Path(dir1, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Local localFile2 = new Local(localDirectory1, file2.getName());
    final OutputStream out2 = localFile2.getOutputStream(false);
    IOUtils.write(content, out2);
    out2.close();
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback() {

        @Override
        public Credentials prompt(final Host bookmark, final String title, final String reason, final LoginOptions options) {
            return new VaultCredentials("test");
        }
    }));
    PreferencesFactory.get().setProperty("factory.vault.class", CryptoVault.class.getName());
    final Host host = new Host(new TestProtocol());
    final Transfer t = new UploadTransfer(host, Collections.singletonList(new TransferItem(dir1, localDirectory1)), new NullFilter<>()).withOptions(new UploadFilterOptions(host).withTimestamp(true));
    assertTrue(new SingleTransferWorker(session, session, t, new TransferOptions(), new TransferSpeedometer(t), new DisabledTransferPrompt() {

        @Override
        public TransferAction prompt(final TransferItem file) {
            return TransferAction.overwrite;
        }
    }, new DisabledTransferErrorCallback(), new DisabledProgressListener(), new DisabledStreamListener(), new DisabledLoginCallback(), new DisabledNotificationService()) {
    }.run(session));
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(dir1));
    final PathAttributes attributes1 = new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(file1);
    assertEquals(1513092263000L, attributes1.getModificationDate());
    assertEquals(1513092263000L, new CryptoListService(session, new SFTPListService(session), cryptomator).list(dir1, new DisabledListProgressListener()).get(file1).attributes().getModificationDate());
    assertEquals(content.length, attributes1.getSize());
    {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
        assertArrayEquals(content, buffer.toByteArray());
    }
    final PathAttributes attributes2 = new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(file2);
    assertEquals(content.length, attributes2.getSize());
    {
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        final InputStream in = new CryptoReadFeature(session, new SFTPReadFeature(session), cryptomator).read(file1, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
        new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(in, buffer);
        assertArrayEquals(content, buffer.toByteArray());
    }
    cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(file1, file2, dir1, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
    localFile1.delete();
    localFile2.delete();
    localDirectory1.delete();
}
Also used : Delete(ch.cyberduck.core.features.Delete) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultLocalDirectoryFeature(ch.cyberduck.core.local.DefaultLocalDirectoryFeature) DisabledTransferErrorCallback(ch.cyberduck.core.transfer.DisabledTransferErrorCallback) SFTPDeleteFeature(ch.cyberduck.core.sftp.SFTPDeleteFeature) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) SFTPReadFeature(ch.cyberduck.core.sftp.SFTPReadFeature) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) Transfer(ch.cyberduck.core.transfer.Transfer) SFTPListService(ch.cyberduck.core.sftp.SFTPListService) TransferSpeedometer(ch.cyberduck.core.transfer.TransferSpeedometer) TransferItem(ch.cyberduck.core.transfer.TransferItem) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) SFTPAttributesFinderFeature(ch.cyberduck.core.sftp.SFTPAttributesFinderFeature) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) SFTPFindFeature(ch.cyberduck.core.sftp.SFTPFindFeature) TransferAction(ch.cyberduck.core.transfer.TransferAction) SingleTransferWorker(ch.cyberduck.core.worker.SingleTransferWorker) TransferOptions(ch.cyberduck.core.transfer.TransferOptions) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) DisabledNotificationService(ch.cyberduck.core.notification.DisabledNotificationService) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) InputStream(java.io.InputStream) UploadFilterOptions(ch.cyberduck.core.transfer.upload.UploadFilterOptions) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DisabledTransferPrompt(ch.cyberduck.core.transfer.DisabledTransferPrompt) UploadTransfer(ch.cyberduck.core.transfer.UploadTransfer) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Aggregations

UploadFilterOptions (ch.cyberduck.core.transfer.upload.UploadFilterOptions)4 Test (org.junit.Test)3 Delete (ch.cyberduck.core.features.Delete)2 DisabledStreamListener (ch.cyberduck.core.io.DisabledStreamListener)2 DisabledNotificationService (ch.cyberduck.core.notification.DisabledNotificationService)2 Transfer (ch.cyberduck.core.transfer.Transfer)2 TransferOptions (ch.cyberduck.core.transfer.TransferOptions)2 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)2 UploadTransfer (ch.cyberduck.core.transfer.UploadTransfer)2 SingleTransferWorker (ch.cyberduck.core.worker.SingleTransferWorker)2 DisabledProgressListener (ch.cyberduck.core.DisabledProgressListener)1 Host (ch.cyberduck.core.Host)1 NullSession (ch.cyberduck.core.NullSession)1 NullTransferSession (ch.cyberduck.core.NullTransferSession)1 Path (ch.cyberduck.core.Path)1 Permission (ch.cyberduck.core.Permission)1 TestProtocol (ch.cyberduck.core.TestProtocol)1 CryptoAttributesFeature (ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature)1 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)1 CryptoListService (ch.cyberduck.core.cryptomator.features.CryptoListService)1