Search in sources :

Example 1 with FTPListService

use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.

the class FTPListServiceTest method testListCryptomator.

@Test
public void testListCryptomator() throws Exception {
    final Path home = new DefaultHomeFinderService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    assertTrue(new CryptoListService(session, new FTPListService(session, null, null), cryptomator).list(vault, new DisabledListProgressListener()).isEmpty());
    new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new FTPWriteFeature(session)), new FTPWriteFeature(session), cryptomator).touch(test, new TransferStatus());
    assertEquals(test, new CryptoListService(session, new FTPListService(session, null, null), cryptomator).list(vault, new DisabledListProgressListener()).get(0));
    cryptomator.getFeature(session, Delete.class, new FTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) DefaultTouchFeature(ch.cyberduck.core.shared.DefaultTouchFeature) FTPDeleteFeature(ch.cyberduck.core.ftp.FTPDeleteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) FTPListService(ch.cyberduck.core.ftp.list.FTPListService) FTPWriteFeature(ch.cyberduck.core.ftp.FTPWriteFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractFTPTest(ch.cyberduck.core.ftp.AbstractFTPTest)

Example 2 with FTPListService

use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.

the class FTPUnixPermissionFeatureTest method testSetUnixPermission.

@Test(expected = InteroperabilityException.class)
public void testSetUnixPermission() throws Exception {
    final FTPWorkdirService workdir = new FTPWorkdirService(session);
    final Path home = workdir.find();
    final Path test = new Path(workdir.find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    new FTPTouchFeature(session).touch(test, new TransferStatus());
    new FTPUnixPermissionFeature(session).setUnixPermission(test, new Permission(666));
    assertEquals("666", new FTPListService(session, null, TimeZone.getDefault()).list(home, new DisabledListProgressListener()).get(test).attributes().getPermission().getMode());
    new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) Permission(ch.cyberduck.core.Permission) FTPListService(ch.cyberduck.core.ftp.list.FTPListService) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 3 with FTPListService

use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.

the class FTPWriteFeatureTest method testWrite.

@Test
public void testWrite() throws Exception {
    final TransferStatus status = new TransferStatus();
    final int length = 1048576;
    final byte[] content = RandomUtils.nextBytes(length);
    status.setLength(content.length);
    final Path home = new DefaultHomeFinderService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path test = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    final CryptoWriteFeature<Void> writer = new CryptoWriteFeature<>(session, new FTPWriteFeature(session), cryptomator);
    final FileHeader header = cryptomator.getFileHeaderCryptor().create();
    status.setHeader(cryptomator.getFileHeaderCryptor().encryptHeader(header));
    status.setNonces(new RotatingNonceGenerator(cryptomator.numberOfChunks(content.length)));
    status.setChecksum(writer.checksum(test, status).compute(new ByteArrayInputStream(content), status));
    status.setLength(content.length);
    final OutputStream out = writer.write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(test));
    final PathAttributes attr = new CryptoAttributesFeature(session, new FTPAttributesFinderFeature(session), cryptomator).find(test);
    assertEquals(content.length, new CryptoListService(session, new FTPListService(session, null, TimeZone.getDefault()), cryptomator).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes().getSize());
    assertEquals(content.length, new CryptoWriteFeature<>(session, new FTPWriteFeature(session), cryptomator).append(test, status.withRemote(attr)).size, 0L);
    final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
    final InputStream in = new CryptoReadFeature(session, new FTPReadFeature(session), cryptomator).read(test, new TransferStatus(), new DisabledConnectionCallback());
    new StreamCopier(status, status).transfer(in, buffer);
    assertArrayEquals(content, buffer.toByteArray());
    cryptomator.getFeature(session, Delete.class, new FTPDeleteFeature(session)).delete(Arrays.asList(test, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) CryptoListService(ch.cyberduck.core.cryptomator.features.CryptoListService) CryptoWriteFeature(ch.cyberduck.core.cryptomator.features.CryptoWriteFeature) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) RotatingNonceGenerator(ch.cyberduck.core.cryptomator.random.RotatingNonceGenerator) FTPDeleteFeature(ch.cyberduck.core.ftp.FTPDeleteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoReadFeature(ch.cyberduck.core.cryptomator.features.CryptoReadFeature) FileHeader(org.cryptomator.cryptolib.api.FileHeader) Path(ch.cyberduck.core.Path) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) PathAttributes(ch.cyberduck.core.PathAttributes) DefaultHomeFinderService(ch.cyberduck.core.shared.DefaultHomeFinderService) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) FTPAttributesFinderFeature(ch.cyberduck.core.ftp.FTPAttributesFinderFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) FTPWriteFeature(ch.cyberduck.core.ftp.FTPWriteFeature) FTPListService(ch.cyberduck.core.ftp.list.FTPListService) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) FTPReadFeature(ch.cyberduck.core.ftp.FTPReadFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractFTPTest(ch.cyberduck.core.ftp.AbstractFTPTest)

Example 4 with FTPListService

use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.

the class FTPMFMTTimestampFeatureTest method testSetTimestamp.

@Test
public void testSetTimestamp() throws Exception {
    final Path home = new FTPWorkdirService(session).find();
    final long modified = System.currentTimeMillis();
    final Path test = new Path(new FTPWorkdirService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    new FTPTouchFeature(session).touch(test, new TransferStatus());
    new FTPMFMTTimestampFeature(session).setTimestamp(test, modified);
    assertEquals(modified / 1000 * 1000, new FTPListService(session, null, TimeZone.getDefault()).list(home, new DisabledListProgressListener()).get(test).attributes().getModificationDate());
    new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) FTPListService(ch.cyberduck.core.ftp.list.FTPListService) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Example 5 with FTPListService

use of ch.cyberduck.core.ftp.list.FTPListService in project cyberduck by iterate-ch.

the class FTPWriteFeatureTest method testReadWrite.

@Test
public void testReadWrite() throws Exception {
    final TransferStatus status = new TransferStatus();
    final byte[] content = "test".getBytes(StandardCharsets.UTF_8);
    status.setLength(content.length);
    final Path test = new Path(new FTPWorkdirService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final OutputStream out = new FTPWriteFeature(session).write(test, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    assertTrue(session.getFeature(Find.class).find(test));
    final PathAttributes attributes = new FTPListService(session, null, TimeZone.getDefault()).list(test.getParent(), new DisabledListProgressListener()).get(test).attributes();
    assertEquals(content.length, attributes.getSize());
    assertEquals(content.length, new FTPWriteFeature(session).append(test, status.withRemote(attributes)).size, 0L);
    {
        final InputStream in = new FTPReadFeature(session).read(test, new TransferStatus().withLength(content.length), new DisabledConnectionCallback());
        final ByteArrayOutputStream buffer = new ByteArrayOutputStream(content.length);
        new StreamCopier(status, status).transfer(in, buffer);
        in.close();
        assertArrayEquals(content, buffer.toByteArray());
    }
    {
        final byte[] buffer = new byte[content.length - 1];
        final InputStream in = new FTPReadFeature(session).read(test, new TransferStatus().withLength(content.length).append(true).withOffset(1L), new DisabledConnectionCallback());
        IOUtils.readFully(in, buffer);
        in.close();
        final byte[] reference = new byte[content.length - 1];
        System.arraycopy(content, 1, reference, 0, content.length - 1);
        assertArrayEquals(reference, buffer);
    }
    new FTPDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledListProgressListener(ch.cyberduck.core.DisabledListProgressListener) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) PathAttributes(ch.cyberduck.core.PathAttributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) FTPListService(ch.cyberduck.core.ftp.list.FTPListService) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest)

Aggregations

FTPListService (ch.cyberduck.core.ftp.list.FTPListService)6 DisabledListProgressListener (ch.cyberduck.core.DisabledListProgressListener)5 DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)5 Path (ch.cyberduck.core.Path)5 Delete (ch.cyberduck.core.features.Delete)5 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)5 IntegrationTest (ch.cyberduck.test.IntegrationTest)5 Test (org.junit.Test)5 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)3 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)2 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)2 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)2 PathAttributes (ch.cyberduck.core.PathAttributes)2 CryptoListService (ch.cyberduck.core.cryptomator.features.CryptoListService)2 AbstractFTPTest (ch.cyberduck.core.ftp.AbstractFTPTest)2 FTPDeleteFeature (ch.cyberduck.core.ftp.FTPDeleteFeature)2 FTPWriteFeature (ch.cyberduck.core.ftp.FTPWriteFeature)2 StreamCopier (ch.cyberduck.core.io.StreamCopier)2 DefaultHomeFinderService (ch.cyberduck.core.shared.DefaultHomeFinderService)2 DefaultVaultRegistry (ch.cyberduck.core.vault.DefaultVaultRegistry)2