Background
I am working on an application which uses spring-integration to retrieve files via ftp. I was using one of the spring-integration's ftp inbound adapter. However even after my repeated tries, I was not able to get it working. So I started looking though the code and found that under the wraps it uses apache commons net api.
Question
Using apache commons net library, I wrote the code locally in the same way and it was not working. Here is the code -
FTPClient client = new FTPClient();
client.connect("x.x.x.x", 21);
client.enterLocalPassiveMode();
client.login("xxx", "xxx");
FTPFile[] files = client.listFiles("/AMNH");
This returns me 0 rows. This is how the spring-integration executes the call - client.listFiles("/AMNH"). So the list of files returned is 0 and even though I have files at the ftp location, the whole application sits idle.
However, If I run the following code, I am able to retrieve the files. I was wondering what is wrong with the method listFiles when we pass parameters and how do we work around it ? I say this because I don't have the luxury of not executing listFiles(String pathName)
FTPClient client = new FTPClient();
client.connect("x.x.x.x", 21);
client.enterLocalPassiveMode();
client.login("xxx", "xxx");
client.changeWorkingDirectory("/AMNH");
FTPFile[] files = client.listFiles("");
Please, take a look into Reference Manual regarding
changeWorkingDirectory
. You only need to extend theDefaultFtpSessionFactory
and implementpostProcessClientAfterConnect()
callback.