Example usage for org.springframework.integration.ftp.session FtpRemoteFileTemplate exists

List of usage examples for org.springframework.integration.ftp.session FtpRemoteFileTemplate exists

Introduction

In this page you can find the example usage for org.springframework.integration.ftp.session FtpRemoteFileTemplate exists.

Prototype

@Override
public boolean exists(final String path) 

Source Link

Document

This particular FTP implementation is based on the FTPClient#getStatus(String) by default, but since not all FTP servers properly implement the STAT command, the framework internal FtpRemoteFileTemplate instances are switched to the FTPClient#listNames(String) for only files operations.

Usage

From source file:org.springframework.integration.ftp.outbound.FtpServerOutboundTests.java

@Test
public void testInt3412FileMode() {
    FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(ftpSessionFactory);
    assertFalse(template.exists("ftpTarget/appending.txt"));
    Message<String> m = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "appending.txt")
            .build();//from  w w w.j a v  a2 s. c o m
    appending.send(m);
    appending.send(m);

    assertLength6(template);

    ignoring.send(m);
    assertLength6(template);
    try {
        failing.send(m);
        fail("Expected exception");
    } catch (MessagingException e) {
        assertThat(e.getCause().getCause().getMessage(), containsString("The destination file already exists"));
    }

}

From source file:org.springframework.integration.ftp.session.FtpRemoteFileTemplateTests.java

@Test
public void testINT3412AppendStatRmdir() throws IOException {
    FtpRemoteFileTemplate template = new FtpRemoteFileTemplate(sessionFactory);
    DefaultFileNameGenerator fileNameGenerator = new DefaultFileNameGenerator();
    fileNameGenerator.setExpression("'foobar.txt'");
    template.setFileNameGenerator(fileNameGenerator);
    template.setRemoteDirectoryExpression(new LiteralExpression("foo/"));
    template.setUseTemporaryFileName(false);
    template.execute(session -> {/*from  w ww. j  av a  2  s .  com*/
        session.mkdir("foo/");
        return session.mkdir("foo/bar/");
    });
    template.append(new GenericMessage<String>("foo"));
    template.append(new GenericMessage<String>("bar"));
    assertTrue(template.exists("foo/foobar.txt"));
    template.executeWithClient((ClientCallbackWithoutResult<FTPClient>) client -> {
        try {
            FTPFile[] files = client.listFiles("foo/foobar.txt");
            assertEquals(6, files[0].getSize());
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    });
    template.execute((SessionCallbackWithoutResult<FTPFile>) session -> {
        assertTrue(session.remove("foo/foobar.txt"));
        assertTrue(session.rmdir("foo/bar/"));
        FTPFile[] files = session.list("foo/");
        assertEquals(0, files.length);
        assertTrue(session.rmdir("foo/"));
    });
    assertFalse(template.getSession().exists("foo"));
}