Amu
Amu

Reputation: 161

Watching/Polling FTP location

Could anyone suggest an open source library in JAVA to monitor FTP location changes? I'm trying to monitor the changes in FTP location and once the changes are detected, changed files are to be copied to a SVN location for commitment.

Upvotes: 2

Views: 3113

Answers (2)

TheUnborn
TheUnborn

Reputation: 27

There is a Spring Integration Solution for this Problem . We will be using FTP Inbound Channel Adapter for this problem. Java WatchService works in Local but not in remote location. Well we be polling and finding out the changes and print the event.

Just Follow this documentation Spring integration documentation for FTP

Upvotes: 0

etxalpo
etxalpo

Reputation: 1176

The Remote Directory Poller for Java (rdp4j) library can help you out with polling an FTP location and notify you with events (such as file added/modified/removed in directory). See User Guide for implementations of FtpDirectory and MyListener in below quick tutorial:

package example

import java.util.concurrent.TimeUnit;
import com.github.drapostolos.rdp4j.DirectoryPoller;
import com.github.drapostolos.rdp4j.spi.PolledDirectory;

public class FtpExample {

    public static void main(String[] args) throws Exception {
        String host = "ftp.mozilla.org";
        String workingDirectory = "pub/addons";
        String username = "anonymous";
        String password = "anonymous";
        PolledDirectory polledDirectory = new FtpDirectory(host, workingDirectory, username, password);

        DirectoryPoller dp = DirectoryPoller.newBuilder()
        .addPolledDirectory(polledDirectory)
        .addListener(new MyListener())
        .setPollingInterval(10, TimeUnit.MINUTES)
        .start();

        TimeUnit.HOURS.sleep(2);

        dp.stop();
    }
}

Upvotes: 7

Related Questions