Search in sources :

Example 1 with SFTPWriteFeature

use of ch.cyberduck.core.sftp.SFTPWriteFeature in project cyberduck by iterate-ch.

the class DefaultCopyFeatureTest method testCopy.

@Test
public void testCopy() throws Exception {
    final Path source = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new SFTPTouchFeature(session).touch(source, new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(524);
    final TransferStatus status = new TransferStatus().withLength(content.length);
    final OutputStream out = new SFTPWriteFeature(session).write(source, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).withLimit(new Long(content.length)).transfer(new ByteArrayInputStream(content), out);
    out.close();
    new DefaultCopyFeature(session).copy(source, target, new TransferStatus(), new DisabledConnectionCallback(), new DisabledStreamListener());
    assertTrue(new DefaultFindFeature(session).find(source));
    assertTrue(new DefaultFindFeature(session).find(target));
    assertEquals(content.length, new DefaultAttributesFinderFeature(session).find(target).getSize());
    new SFTPDeleteFeature(session).delete(Arrays.asList(source, target), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) OutputStream(java.io.OutputStream) SFTPWriteFeature(ch.cyberduck.core.sftp.SFTPWriteFeature) SFTPDeleteFeature(ch.cyberduck.core.sftp.SFTPDeleteFeature) SFTPTouchFeature(ch.cyberduck.core.sftp.SFTPTouchFeature) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Example 2 with SFTPWriteFeature

use of ch.cyberduck.core.sftp.SFTPWriteFeature in project cyberduck by iterate-ch.

the class DefaultDownloadFeatureTest method testTransferUnknownSize.

@Test
public void testTransferUnknownSize() throws Exception {
    final Path test = new Path(new SFTPHomeDirectoryService(session).find(), UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    session.getFeature(Touch.class).touch(test, new TransferStatus());
    final byte[] content = new byte[1];
    new Random().nextBytes(content);
    {
        final TransferStatus status = new TransferStatus().withLength(content.length);
        final OutputStream out = new SFTPWriteFeature(session).write(test, status, new DisabledConnectionCallback());
        assertNotNull(out);
        new StreamCopier(status, status).withLimit(new Long(content.length)).transfer(new ByteArrayInputStream(content), out);
        out.close();
    }
    final Local local = new Local(System.getProperty("java.io.tmpdir"), UUID.randomUUID().toString());
    {
        final TransferStatus status = new TransferStatus().withLength(-1L);
        new DefaultDownloadFeature(new SFTPReadFeature(session)).download(test, local, new BandwidthThrottle(BandwidthThrottle.UNLIMITED), new DisabledStreamListener(), status, new DisabledConnectionCallback());
    }
    final byte[] buffer = new byte[content.length];
    final InputStream in = local.getInputStream();
    IOUtils.readFully(in, buffer);
    in.close();
    assertArrayEquals(content, buffer);
    final Delete delete = session.getFeature(Delete.class);
    delete.delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) DisabledStreamListener(ch.cyberduck.core.io.DisabledStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) Local(ch.cyberduck.core.Local) SFTPWriteFeature(ch.cyberduck.core.sftp.SFTPWriteFeature) Touch(ch.cyberduck.core.features.Touch) SFTPReadFeature(ch.cyberduck.core.sftp.SFTPReadFeature) Random(java.util.Random) BandwidthThrottle(ch.cyberduck.core.io.BandwidthThrottle) ByteArrayInputStream(java.io.ByteArrayInputStream) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) StreamCopier(ch.cyberduck.core.io.StreamCopier) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Example 3 with SFTPWriteFeature

use of ch.cyberduck.core.sftp.SFTPWriteFeature in project cyberduck by iterate-ch.

the class SFTPMoveFeatureTest method testMoveFile.

@Test
public void testMoveFile() throws Exception {
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path folder = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final CryptoVault cryptomator = new CryptoVault(vault);
    cryptomator.create(session, new VaultCredentials("test"), new DisabledPasswordStore(), vaultVersion);
    session.withRegistry(new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator));
    cryptomator.getFeature(session, Directory.class, new SFTPDirectoryFeature(session)).mkdir(folder, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(folder));
    final Path template = new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path file = new CryptoTouchFeature<>(session, new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new SFTPWriteFeature(session)), new SFTPWriteFeature(session), cryptomator), new SFTPWriteFeature(session), cryptomator).touch(template, new TransferStatus()).withAttributes(new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(template));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(file));
    final Move move = cryptomator.getFeature(session, Move.class, new SFTPMoveFeature(session));
    // rename file
    final Path fileRenamed = move.move(file, new Path(folder, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file)), new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
    assertEquals(fileRenamed.attributes(), new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(fileRenamed));
    assertFalse(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(file));
    assertEquals(fileRenamed.attributes(), new CryptoAttributesFeature(session, new SFTPAttributesFinderFeature(session), cryptomator).find(fileRenamed));
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(fileRenamed));
    cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(fileRenamed, folder), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : SFTPAttributesFinderFeature(ch.cyberduck.core.sftp.SFTPAttributesFinderFeature) Delete(ch.cyberduck.core.features.Delete) SFTPFindFeature(ch.cyberduck.core.sftp.SFTPFindFeature) SFTPWriteFeature(ch.cyberduck.core.sftp.SFTPWriteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) Move(ch.cyberduck.core.features.Move) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoTouchFeature(ch.cyberduck.core.cryptomator.features.CryptoTouchFeature) SFTPDirectoryFeature(ch.cyberduck.core.sftp.SFTPDirectoryFeature) Directory(ch.cyberduck.core.features.Directory) Path(ch.cyberduck.core.Path) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) SFTPDeleteFeature(ch.cyberduck.core.sftp.SFTPDeleteFeature) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) CryptoAttributesFeature(ch.cyberduck.core.cryptomator.features.CryptoAttributesFeature) DefaultTouchFeature(ch.cyberduck.core.shared.DefaultTouchFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) SFTPMoveFeature(ch.cyberduck.core.sftp.SFTPMoveFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Example 4 with SFTPWriteFeature

use of ch.cyberduck.core.sftp.SFTPWriteFeature in project cyberduck by iterate-ch.

the class SFTPMoveFeatureTest method testMoveToDifferentFolderLongFilenameCryptomator.

@Test
public void testMoveToDifferentFolderLongFilenameCryptomator() throws Exception {
    assumeTrue(vaultVersion == CryptoVault.VAULT_VERSION_DEPRECATED);
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, UUID.randomUUID().toString(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.file));
    final Path targetFolder = new Path(vault, new AlphanumericRandomStringService(130).random(), EnumSet.of(Path.Type.directory));
    final Path target = new Path(targetFolder, new AlphanumericRandomStringService(130).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));
    new CryptoTouchFeature<>(session, new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new SFTPWriteFeature(session)), new SFTPWriteFeature(session), cryptomator), new SFTPWriteFeature(session), cryptomator).touch(source, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    cryptomator.getFeature(session, Directory.class, new SFTPDirectoryFeature(session)).mkdir(targetFolder, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(targetFolder));
    cryptomator.getFeature(session, Move.class, new SFTPMoveFeature(session)).move(source, target, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
    assertFalse(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(target));
    cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(target, targetFolder, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Path(ch.cyberduck.core.Path) Delete(ch.cyberduck.core.features.Delete) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) SFTPWriteFeature(ch.cyberduck.core.sftp.SFTPWriteFeature) SFTPDeleteFeature(ch.cyberduck.core.sftp.SFTPDeleteFeature) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) Move(ch.cyberduck.core.features.Move) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) CryptoTouchFeature(ch.cyberduck.core.cryptomator.features.CryptoTouchFeature) SFTPDirectoryFeature(ch.cyberduck.core.sftp.SFTPDirectoryFeature) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) Directory(ch.cyberduck.core.features.Directory) SFTPMoveFeature(ch.cyberduck.core.sftp.SFTPMoveFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Example 5 with SFTPWriteFeature

use of ch.cyberduck.core.sftp.SFTPWriteFeature in project cyberduck by iterate-ch.

the class SFTPMoveFeatureTest method testMoveFolderWithFile.

@Test
public void testMoveFolderWithFile() throws Exception {
    final Path home = new SFTPHomeDirectoryService(session).find();
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path folder = new Path(vault, "folder-1", EnumSet.of(Path.Type.directory));
    final Path file = new Path(folder, "file-1", 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));
    cryptomator.getFeature(session, Directory.class, new SFTPDirectoryFeature(session)).mkdir(folder, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(folder));
    new CryptoTouchFeature<>(session, new CryptoTouchFeature<>(session, new DefaultTouchFeature<>(new SFTPWriteFeature(session)), new SFTPWriteFeature(session), cryptomator), new SFTPWriteFeature(session), cryptomator).touch(file, new TransferStatus());
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(file));
    final Move move = cryptomator.getFeature(session, Move.class, new SFTPMoveFeature(session));
    // rename file
    final Path fileRenamed = new Path(folder, "f1", EnumSet.of(Path.Type.file));
    move.move(file, fileRenamed, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
    assertFalse(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(file));
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(fileRenamed));
    // rename folder
    final Path folderRenamed = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    move.move(folder, folderRenamed, new TransferStatus(), new Delete.DisabledCallback(), new DisabledConnectionCallback());
    assertFalse(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(folder));
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(folderRenamed));
    final Path fileRenamedInRenamedFolder = new Path(folderRenamed, "f1", EnumSet.of(Path.Type.file));
    assertTrue(new CryptoFindFeature(session, new SFTPFindFeature(session), cryptomator).find(fileRenamedInRenamedFolder));
    cryptomator.getFeature(session, Delete.class, new SFTPDeleteFeature(session)).delete(Arrays.asList(fileRenamedInRenamedFolder, folderRenamed, vault), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
Also used : Delete(ch.cyberduck.core.features.Delete) SFTPFindFeature(ch.cyberduck.core.sftp.SFTPFindFeature) SFTPWriteFeature(ch.cyberduck.core.sftp.SFTPWriteFeature) DefaultVaultRegistry(ch.cyberduck.core.vault.DefaultVaultRegistry) DefaultFindFeature(ch.cyberduck.core.shared.DefaultFindFeature) Move(ch.cyberduck.core.features.Move) TransferStatus(ch.cyberduck.core.transfer.TransferStatus) CryptoTouchFeature(ch.cyberduck.core.cryptomator.features.CryptoTouchFeature) SFTPDirectoryFeature(ch.cyberduck.core.sftp.SFTPDirectoryFeature) Directory(ch.cyberduck.core.features.Directory) Path(ch.cyberduck.core.Path) VaultCredentials(ch.cyberduck.core.vault.VaultCredentials) SFTPDeleteFeature(ch.cyberduck.core.sftp.SFTPDeleteFeature) CryptoFindFeature(ch.cyberduck.core.cryptomator.features.CryptoFindFeature) DisabledLoginCallback(ch.cyberduck.core.DisabledLoginCallback) AlphanumericRandomStringService(ch.cyberduck.core.AlphanumericRandomStringService) DisabledPasswordStore(ch.cyberduck.core.DisabledPasswordStore) DisabledPasswordCallback(ch.cyberduck.core.DisabledPasswordCallback) SFTPHomeDirectoryService(ch.cyberduck.core.sftp.SFTPHomeDirectoryService) DisabledConnectionCallback(ch.cyberduck.core.DisabledConnectionCallback) SFTPMoveFeature(ch.cyberduck.core.sftp.SFTPMoveFeature) Test(org.junit.Test) IntegrationTest(ch.cyberduck.test.IntegrationTest) AbstractSFTPTest(ch.cyberduck.core.sftp.AbstractSFTPTest)

Aggregations

DisabledLoginCallback (ch.cyberduck.core.DisabledLoginCallback)27 Path (ch.cyberduck.core.Path)27 Delete (ch.cyberduck.core.features.Delete)27 AbstractSFTPTest (ch.cyberduck.core.sftp.AbstractSFTPTest)27 SFTPHomeDirectoryService (ch.cyberduck.core.sftp.SFTPHomeDirectoryService)27 SFTPWriteFeature (ch.cyberduck.core.sftp.SFTPWriteFeature)27 TransferStatus (ch.cyberduck.core.transfer.TransferStatus)27 IntegrationTest (ch.cyberduck.test.IntegrationTest)27 Test (org.junit.Test)27 SFTPDeleteFeature (ch.cyberduck.core.sftp.SFTPDeleteFeature)24 DisabledPasswordCallback (ch.cyberduck.core.DisabledPasswordCallback)22 DisabledPasswordStore (ch.cyberduck.core.DisabledPasswordStore)22 DefaultVaultRegistry (ch.cyberduck.core.vault.DefaultVaultRegistry)22 VaultCredentials (ch.cyberduck.core.vault.VaultCredentials)22 CryptoFindFeature (ch.cyberduck.core.cryptomator.features.CryptoFindFeature)18 AlphanumericRandomStringService (ch.cyberduck.core.AlphanumericRandomStringService)16 DefaultFindFeature (ch.cyberduck.core.shared.DefaultFindFeature)14 DisabledConnectionCallback (ch.cyberduck.core.DisabledConnectionCallback)13 CryptoTouchFeature (ch.cyberduck.core.cryptomator.features.CryptoTouchFeature)9 Directory (ch.cyberduck.core.features.Directory)9