Results 1 to 2 of 2

Thread: int-ftp:inbound-channel-adapter

  1. #1
    Join Date
    Dec 2012
    Posts
    3

    Default int-ftp:inbound-channel-adapter

    I see that "The FTP Inbound Channel Adapter is a special listener that will connect to the FTP server and will
    listen for the remote directory events (e.g., new file created) at which point it will initiate a file transfer." in the Spring Integration Reference.
    I writed the xml like this.
    Code:
    <int-ftp:inbound-channel-adapter id="ftpInbound"
    		channel="ftpChannel" session-factory="ftpsessionFactory"
    		 auto-create-local-directory="true"
    		 remote-file-separator="/"
    		 filename-pattern="*.txt"
    		delete-remote-files="true" remote-directory="/content"
                               local-directory="file:D:/ftpfile/test001">
    		<int:poller id="poller" fixed-rate="1000" max-messages-per-poll="15">
    		</int:poller>
    	     </int-ftp:inbound-channel-adapter>
    but the remote-directory content has many folder,like newspaper,magazine and so on. how can i listen the files in newspaper,magazine. thank you very much.

  2. #2
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,016

    Default

    The FTP adapter uses Apache Commons FtpClient under the covers; it doesn't support recursive file walking.

    If you don't have too many subdirectories, simply configure an adapter for each.

    Otherwise, you could subclass the DefaultFtpSessionFactory (and FtpSession) and override FtpSession.list() to recursively walk the directory tree.

    However, this would "flatten" the directory tree, copying each file into a single local directory.

    To retain the directory structure locally, you'd need to also subclass the FtpInboundFileSynchronizer and override the synchronizeToLocalDirectory() method.

    If you decide to go this route, please consider submitting to the Spring Integration Extensions repo. https://github.com/SpringSource/spri...ion-extensions.

    Alternatively, you might be able to do what you want using the <ftp:outbound-gateway/> to list and then GET (and perhaps remove) each file....

    Code:
    	<int-ftp:outbound-gateway id="gatewayLS" cache-sessions="false"
    		session-factory="ftpSessionFactory"
    		request-channel="inbound"
    		command="ls"
    		command-options=""
    		expression="'./*/*.txt'"
    		reply-channel="toSplitter"/>
    
    	<int:channel id="toSplitter" />
    
    	<int:splitter id="splitter" input-channel="toSplitter" output-channel="toGet"/>
    
    	<int:channel id="toGet" />
    
    	<int-ftp:outbound-gateway id="gatewayGET" cache-sessions="false"
    		local-directory="/tmp/frodo"
    		session-factory="ftpSessionFactory"
    		request-channel="toGet"
    		reply-channel="toRemoveChannel"
    		command="get"
    		command-options="-P"
    		expression="payload.filename"/>
    However, this, too, will flatten the directory - we would need to support an expression in 'local-directory' to support retaining the tree structure. I have opened a new feature JIRA for this https://jira.springsource.org/browse/INT-2866.

    The ftp sample shows how to remove the remote file after a successful GET.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •