Search in sources :

Example 1 with FileTransferException

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

the class ApacheFtpClientImpl method setKeepAliveTimeout.

@Override
public void setKeepAliveTimeout(long seconds) throws FileTransferException {
    try {
        acquireLock();
        ftpClient().setControlKeepAliveTimeout(seconds);
    } catch (IOException e) {
        throw new FileTransferException(e);
    } finally {
        releaseLock();
    }
}
Also used : FileTransferException(com.adaptris.filetransfer.FileTransferException) IOException(java.io.IOException)

Example 2 with FileTransferException

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

the class SftpClient method listFiles.

private List<ChannelSftp.LsEntry> listFiles(String dirname) throws IOException, FileTransferException {
    checkConnected();
    List<ChannelSftp.LsEntry> result = new ArrayList<>();
    try {
        acquireLock();
        String path = defaultIfBlank(dirname, CURRENT_DIR);
        log("DIR {}", path);
        Vector<LsEntry> v = sessionWrapper.getSftpChannel().ls(path);
        for (LsEntry entry : v) {
            if (!(entry.getFilename().equals(CURRENT_DIR) || entry.getFilename().equals(PARENT_DIR))) {
                result.add(entry);
            }
        }
    } catch (Exception e) {
        throw SftpException.wrapException("Could not list files in " + dirname, e);
    } finally {
        releaseLock();
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) LsEntry(com.jcraft.jsch.ChannelSftp.LsEntry) FileTransferException(com.adaptris.filetransfer.FileTransferException) FtpException(com.adaptris.ftp.FtpException) IOException(java.io.IOException)

Example 3 with FileTransferException

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

the class SftpClient method lastModified.

/**
 * @see FileTransferClient#lastModified(java.lang.String)
 */
@Override
public long lastModified(String remoteFile) throws IOException, FileTransferException {
    long mtime;
    checkConnected();
    try {
        acquireLock();
        log("STAT {}", remoteFile);
        SftpATTRS attr = sessionWrapper.getSftpChannel().stat(remoteFile);
        mtime = (long) attr.getMTime() * 1000;
    } catch (Exception e) {
        throw SftpException.wrapException("Could not get lastModified on [" + remoteFile + "]", e);
    } finally {
        releaseLock();
    }
    return mtime;
}
Also used : SftpATTRS(com.jcraft.jsch.SftpATTRS) FileTransferException(com.adaptris.filetransfer.FileTransferException) FtpException(com.adaptris.ftp.FtpException) IOException(java.io.IOException)

Example 4 with FileTransferException

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

the class RelaxedFtpConsumerTest method testSingleFileConsumeDeleteFails.

@Test
public void testSingleFileConsumeDeleteFails() throws Exception {
    setFilesToConsume(new String[] { "/MySingleFile.txt" }, new String[] { "My file payload" }, new long[] { calendarOneYearAgo.getTimeInMillis() });
    doThrow(new FileTransferException("expected")).when(mockFileTransferClient).delete(anyString());
    LifecycleHelper.init(consumer);
    LifecycleHelper.start(consumer);
    waitForConsumer(1, 3000);
    assertEquals(1, messageListener.getMessages().size());
}
Also used : FileTransferException(com.adaptris.filetransfer.FileTransferException) Test(org.junit.Test)

Example 5 with FileTransferException

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

the class RelaxedFtpConsumerTest method testDirFailsIncorrectPathConsume.

@Test
public void testDirFailsIncorrectPathConsume() throws Exception {
    setFilesToConsume(new String[] { "/MySingleFile.txt" }, new String[] { "My file payload" }, new long[] { calendarOneYearAgo.getTimeInMillis() });
    when(mockFileTransferClient.dir(DIR_ROOT)).thenThrow(new FileTransferException("testDirFailsIncorrectPathConsume"));
    when(mockFileTransferClient.dir(eq(DIR_ROOT), isA(FileFilter.class))).thenThrow(new FileTransferException("testDirFailsIncorrectPathConsume"));
    LifecycleHelper.init(consumer);
    LifecycleHelper.start(consumer);
    waitForConsumer(1, 1000);
    assertEquals(0, messageListener.getMessages().size());
}
Also used : FileTransferException(com.adaptris.filetransfer.FileTransferException) FileFilter(java.io.FileFilter) Test(org.junit.Test)

Aggregations

FileTransferException (com.adaptris.filetransfer.FileTransferException)8 Test (org.junit.Test)5 IOException (java.io.IOException)3 FtpException (com.adaptris.ftp.FtpException)2 FileTransferClient (com.adaptris.filetransfer.FileTransferClient)1 LsEntry (com.jcraft.jsch.ChannelSftp.LsEntry)1 SftpATTRS (com.jcraft.jsch.SftpATTRS)1 File (java.io.File)1 FileFilter (java.io.FileFilter)1 ArrayList (java.util.ArrayList)1