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;
}
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);
}
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);
}
}
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);
}
}
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);
}
}
Aggregations