Search in sources :

Example 26 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class AggregatingFtpConsumer method multiple.

private List<AdaptrisMessage> multiple(ConfigWrapper cfg, AdaptrisMessageFactory factory) throws Exception {
    FileTransferClient ftpClient = cfg.remote.connect(cfg.endpoint);
    String pollDirectory = cfg.remote.getDirectoryRoot(cfg.endpoint);
    boolean additionalDebug = cfg.remote.additionalDebug();
    List<AdaptrisMessage> result = new ArrayList<>();
    try {
        if (additionalDebug) {
            log.trace("Polling {}", pollDirectory);
        }
        String[] files = ftpClient.dir(pollDirectory, FsHelper.createFilter(cfg.filterExpression, fileFilterImp()));
        if (additionalDebug) {
            log.trace("There are potentially [{}] messages to aggregate", files.length);
        }
        for (int i = 0; i < files.length; i++) {
            String fullPath = pollDirectory + FORWARD_SLASH + FtpHelper.getFilename(files[i], cfg.remote.windowsWorkaround());
            result.add(fetch(ftpClient, fullPath, additionalDebug, factory));
        }
    } finally {
        cfg.remote.disconnect(ftpClient);
    }
    return result;
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) FileTransferClient(com.adaptris.filetransfer.FileTransferClient) ArrayList(java.util.ArrayList) InputFieldHint(com.adaptris.annotation.InputFieldHint)

Example 27 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class AggregatingFtpConsumer method deleteFilesQuietly.

private void deleteFilesQuietly(List<AdaptrisMessage> msgs, ConfigWrapper cfg) throws Exception {
    FileTransferClient ftpClient = cfg.remote.connect(cfg.endpoint);
    for (AdaptrisMessage msg : msgs) {
        String file = (String) msg.getObjectHeaders().get(OBJ_METADATA_KEY_FILENAME);
        try {
            ftpClient.delete(file);
        } catch (Exception e) {
            if (cfg.remote.additionalDebug()) {
                log.trace("Failed to delete [{}]", file);
            }
        }
    }
    cfg.remote.disconnect(ftpClient);
}
Also used : AdaptrisMessage(com.adaptris.core.AdaptrisMessage) FileTransferClient(com.adaptris.filetransfer.FileTransferClient) ServiceException(com.adaptris.core.ServiceException)

Example 28 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class TestCommonsNetFtp method testGetLastModifiedWithTimezone.

@Test
public void testGetLastModifiedWithTimezone() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testGetLastModifiedWithTimezone");
        FileTransferClient client = connectClientImpl();
        client.chdir(getRemoteGetDirectory());
        long mtime = client.lastModified(getRemoteGetFilename());
        client.disconnect();
        CommonsNetFtpClient tzClient = (CommonsNetFtpClient) connectClientImpl();
        tzClient.setServerTimezone(TimeZone.getTimeZone(ALTERNATE_TZ));
        tzClient.chdir(getRemoteGetDirectory());
        long tztime = tzClient.lastModified(getRemoteGetFilename());
        tzClient.disconnect();
        logR.debug("testGetLastModifiedWithTimezone : " + new Date(tztime));
        assertNotSame("" + new Date(mtime), mtime, tztime);
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) CommonsNetFtpClient(com.adaptris.ftp.CommonsNetFtpClient) Date(java.util.Date) Test(org.junit.Test)

Example 29 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class TestCommonsNetFtp method testGetLastModifiedDateWithTimezone.

@Test
public void testGetLastModifiedDateWithTimezone() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testGetLastModifiedDateWithTimezone");
        FileTransferClient client = connectClientImpl();
        client.chdir(getRemoteGetDirectory());
        Date mtime = client.lastModifiedDate(getRemoteGetFilename());
        client.disconnect();
        CommonsNetFtpClient tzClient = (CommonsNetFtpClient) connectClientImpl();
        tzClient.setServerTimezone(TimeZone.getTimeZone(ALTERNATE_TZ));
        tzClient.chdir(getRemoteGetDirectory());
        Date tzDate = tzClient.lastModifiedDate(getRemoteGetFilename());
        tzClient.disconnect();
        logR.debug("testGetLastModifiedWithTimezone : " + tzDate);
        assertNotSame("" + mtime, mtime, tzDate);
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : FileTransferClient(com.adaptris.filetransfer.FileTransferClient) CommonsNetFtpClient(com.adaptris.ftp.CommonsNetFtpClient) Date(java.util.Date) Test(org.junit.Test)

Example 30 with FileTransferClient

use of com.adaptris.filetransfer.FileTransferClient in project interlok by adaptris.

the class TestSftp method testListBadDirectory.

@Test
public void testListBadDirectory() throws Exception {
    Assume.assumeTrue(areTestsEnabled());
    String oldName = Thread.currentThread().getName();
    try {
        Thread.currentThread().setName("testListBadDirectory");
        FileTransferClient client = connectClientImpl();
        try {
            Random r = new Random();
            String dir = config.getProperty(SFTP_GET_REMOTEDIR) + "/" + r.nextInt();
            assertFalse(client.isDirectory(dir));
            client.dir(dir);
            fail("LS of  " + dir + " should not work");
        } catch (Exception e) {
            client.disconnect();
        }
    } finally {
        Thread.currentThread().setName(oldName);
    }
}
Also used : Random(java.util.Random) FileTransferClient(com.adaptris.filetransfer.FileTransferClient) IOException(java.io.IOException) Test(org.junit.Test)

Aggregations

FileTransferClient (com.adaptris.filetransfer.FileTransferClient)39 Test (org.junit.Test)30 File (java.io.File)4 IOException (java.io.IOException)4 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)3 PasswordException (com.adaptris.security.exc.PasswordException)3 CoreException (com.adaptris.core.CoreException)2 ProduceException (com.adaptris.core.ProduceException)2 CommonsNetFtpClient (com.adaptris.ftp.CommonsNetFtpClient)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 After (org.junit.After)2 InputFieldHint (com.adaptris.annotation.InputFieldHint)1 FileNameCreator (com.adaptris.core.FileNameCreator)1 ServiceException (com.adaptris.core.ServiceException)1 FileTransferException (com.adaptris.filetransfer.FileTransferException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Random (java.util.Random)1