[ 
https://issues.apache.org/activemq/browse/SM-1624?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=48033#action_48033
 ] 

Lars Heinemann commented on SM-1624:
------------------------------------

I think the problem is that the ftp server you are using doesn't support the 
LIST comand on files correctly. (just a guess)
For this I prepared a patch reusing your suggested fix. Could you please try 
the below patch and give feedback?

Thanks in advance.
Lars


{noformat}
Index: 
deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java
===================================================================
--- 
deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java
 (revision 725298)
+++ 
deployables/bindingcomponents/servicemix-ftp/src/main/java/org/apache/servicemix/ftp/FtpPollerEndpoint.java
 (working copy)
@@ -272,7 +272,7 @@
             }
         });
     }
-
+    
     protected boolean processFileAndDelete(String file) {
         FTPClient ftp = null;
         boolean unlock = true;
@@ -281,7 +281,7 @@
             if (logger.isDebugEnabled()) {
                 logger.debug("Processing file " + file);
             }
-            if (ftp.listFiles(file).length > 0) {
+            if (isFileExistingOnServer(ftp, file)) {
                 // Process the file. If processing fails, an exception should 
be thrown.
                 processFile(ftp, file);
                 // Processing is successful
@@ -305,6 +305,36 @@
         return unlock;
     }
 
+    /**
+     * checks if file specified exists on server
+     * 
+     * @param ftp       the ftp client
+     * @param file      the full file path
+     * @return          true if found on server
+     */
+    private boolean isFileExistingOnServer(FTPClient ftp, String file) throws 
IOException {
+        boolean foundFile = false;
+        int lastIndex = file.lastIndexOf("/");
+        String directory = ".";
+        String rawName = file;
+        if (lastIndex > 0) { 
+            directory = file.substring(0, lastIndex);
+            rawName = file.substring(lastIndex + 1);
+        }
+
+        FTPFile[] files = listFiles(ftp, directory);
+        if (files.length > 0) {
+            for (FTPFile f : files) {
+                if (f.getName().equals(rawName)) {
+                    foundFile = true;
+                    break;
+                }
+            }
+        }
+
+        return foundFile;
+    }
+    
     protected void processFile(FTPClient ftp, String file) throws Exception {
         InputStream in = ftp.retrieveFileStream(file);
         InOnly exchange = getExchangeFactory().createInOnlyExchange();
{noformat}

> Skipping file xxxxxxx: the file no longer exists on the server
> --------------------------------------------------------------
>
>                 Key: SM-1624
>                 URL: https://issues.apache.org/activemq/browse/SM-1624
>             Project: ServiceMix
>          Issue Type: Improvement
>          Components: servicemix-ftp
>         Environment: Linux
>            Reporter: Bhaskar Dabbigodla
>             Fix For: 3.2.1, 3.2.2
>
>
> I am getting the following message and the file scheduled for processing is 
> not getting delivered to the FtpSender. 
> 2008-10-09 10:52:06,810 | DEBUG | rvicemix.ftp.FtpPollerEndpoint  257 | 
> Scheduling file 
> /translated/HotelContent/HotelContent_nl_NL_2008-10-09-10_50_00_48.xml for 
> processing
> 2008-10-09 10:52:06,814 | DEBUG | rvicemix.ftp.FtpPollerEndpoint  282 | 
> Processing file 
> /translated/HotelContent/HotelContent_nl_NL_2008-10-09-10_50_00_48.xml
> Reason is as shown below.
> 2008-10-09 10:52:06,918 | DEBUG | rvicemix.ftp.FtpPollerEndpoint  298 | 
> Skipping 
> /translated/HotelContent/HotelContent_nl_NL_2008-10-09-10_50_00_48.xml: the 
> file no longer exists on the server
> In my case I am polling at directory but not for particular  file on FTP 
> server. So I have modified the source in processFileAndDelete method of 
> org/apache/servicemix/ftp/FtpPollerEndpoint.java as shown below.
> Initial condition:
>  if (ftp.listFiles(directory).length > 0) {
> After my change
>             int lastIndex = file.lastIndexOf("/");
>             String directory = ".";
>             if (lastIndex > 0) {
>                 directory =  file.substring(0, lastIndex);
>             }
>             if (ftp.listFiles(directory).length > 0) {
> I have tested this on both 3.2.1 and 3.2.2 versions. So please review it and 
> incorporate the change in latest source.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to