static void deleteFileQuitely( @Nullable final GridFtpClient client, @Nullable final String filename) { try { if (client != null) { client.deleteFile(filename); } } catch (final RuntimeException e) { return; // Ignore error } }
@Test(groups = "integration") public void ftpOps() { final GridFtpClient gridFtpClient = gridFtpClientFactory.getGridFtpClient(Credentials.get(hostProxySupplier.get())); final String randomDir = System.getProperty("java.io.tmpdir") + File.separator + UUID.randomUUID().toString(); final String mooFile = randomDir + File.separator + "moo"; try { assert !gridFtpClient.exists(randomDir); gridFtpClient.makeDir(randomDir); assert gridFtpClient.exists(randomDir); assert Iterables.isEmpty(gridFtpClient.list(randomDir)); assert !gridFtpClient.exists(mooFile); gridFtpClient.put(mooFile, new ByteArrayInputStream("Hello World".getBytes())); assert gridFtpClient.exists(mooFile); assert Iterables.getOnlyElement(gridFtpClient.list(randomDir)).getPath().equals(mooFile); assert !Iterables.getOnlyElement(gridFtpClient.list(randomDir)).isDirectory(); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); gridFtpClient.get(mooFile, outputStream); assert new String(outputStream.toByteArray()).equals("Hello World"); assert gridFtpClient.exists(mooFile); gridFtpClient.deleteFile(mooFile); assert !gridFtpClient.exists(mooFile); assert Iterables.isEmpty(gridFtpClient.list(randomDir)); assert gridFtpClient.exists(randomDir); gridFtpClient.deleteDir(randomDir); assert !gridFtpClient.exists(randomDir); } finally { deleteFileQuitely(gridFtpClient, mooFile); deleteDirectoryQuitely(gridFtpClient, randomDir); } }