Validating if a file exists in specific ftp server location

8/19/2021

I need to verify if the file has been completed and generated in a specific ftp location. I am using a java project with Kubernetes - spring boot and I am wondering if there is a way to do a check on a given ftp server, do I need to write a shell script that needs to be executed?

The file I am checking if it exists, it is saved in kubernetes persistence volume , and nifi will copy this file into another ftp server. Kubernetes has the configuration of the volume along with the mounting, but not for the other ftp server which nifi will be using. Thank you

-- codeDev
apache-nifi
ftp
java
kubernetes
spring-boot

1 Answer

8/20/2021

using apache common net library can help you here

pom.xml dependency:

<dependency>
    <groupId>commons-net</groupId>
    <artifactId>commons-net</artifactId>
    <version>3.8.0</version>
</dependency>

//code snippet

boolean checkDirectoryExists(String dirPath) throws IOException {
    ftpClient.changeWorkingDirectory(dirPath);
    returnCode = ftpClient.getReplyCode();
    if (returnCode == 550) {
        return false;
    }
    return true;
}
-- vaibhavsahu
Source: StackOverflow