crazy4groovy
8/9/2011 - 8:03 PM

Simple FTP file retrieval sample (Groovy)

Simple FTP file retrieval sample (Groovy)

@Grab(group='commons-net', module='commons-net', version='2.0')
import org.apache.commons.net.ftp.FTPClient

println("About to connect....");
new FTPClient().with {
    connect "some-server.some-domain.com"
    enterLocalPassiveMode()
    login "your-username", "your-password"
    changeWorkingDirectory "/var/appl/some/remote/dir/"
    def incomingFile = new File("some-file-to-retrieve.log")
    incomingFile.withOutputStream { ostream -> retrieveFile "some-file-to-retrieve.log", ostream }
    disconnect()
}
println("                      ...Done.");