I'm trying to check the existance of a file in an FTP server using Spring Integration but it doesn't seem to work. It works fine with directories but not with files. In documentation is mentioned that works with directories and files. Am I building the path correctly?
private DefaultFtpSessionFactory getFTPFactory() {
DefaultFtpSessionFactory defaultFtpSessionFactory = new DefaultFtpSessionFactory();
defaultFtpSessionFactory.setHost("localhost");
defaultFtpSessionFactory.setPort(21);
defaultFtpSessionFactory.setUsername("foo");
defaultFtpSessionFactory.setPassword("pass");
return defaultFtpSessionFactory;
}
public boolean getFTPFiles() throws IOException {
DefaultFtpSessionFactory defaultFtpSessionFactory = getFTPFactory();
FtpSession ftpSession = defaultFtpSessionFactory.getSession();
FTPClient clientInstance = ftpSession.getClientInstance();
clientInstance.enterLocalPassiveMode();
return ftpSession.exists("/ftp/foo/study/download/test_1.txt");
}
We don't know if you path is correct. The logic in the
FtpSession.exists()
is like this:So, it tries to list the provided path in the user working dir. If not it tries to switch a working dir to the provided path, which is not going to work for file name apparently...
I can suggest to try with the
FtpRemoteFileTemplate.exists()
. See its JavaDocs:I'm not sure about
localPassive/ActiveMode
...Maybe there is a way to investigate a server logs to determine the issue why it doesn't let you to see that file?