groovyapache-nifisftp

Apache Nifi ExecuteGroovyScript: use FTP client inside script


I'm trying to realize inside ExecuteGroovyScript something like:

  import org.apache.commons.net.ftp.FTPClient
  import org.apache.commons.net.ftp.FTP

  def ftpClient = new FTPClient()

  try{
    ftpClient.connect("host")
    // some logic
  } finally {
    if (ftpClient.isConnected()) {
        try {
            ftpClient.logout()
            ftpClient.disconnect()
        } catch (IOException e) {
            // 
        }
    }
 }

But I receive the exception: Unable to resolve class : org.apache.commons.net.ftp.FTPClient

May be there no way to realize FTP connection inside ExecuteGroovyScript ?


Solution

  • The nifi-scripting-nar doesn't include commons-net. You can use @Grab to add the dependency, see my blog post for an example of how to do this.