Skip to content

Instantly share code, notes, and snippets.

@mgdelacroix
Created April 19, 2013 10:19
Show Gist options
  • Save mgdelacroix/5419444 to your computer and use it in GitHub Desktop.
Save mgdelacroix/5419444 to your computer and use it in GitHub Desktop.
FTPClient test. Download All Things!
@Grab(group='commons-net', module='commons-net', version='2.0')
import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTPFile
new FTPClient().with {
connect '61.135.158.199'
println replyString
enterLocalPassiveMode()
login('anonymous', '')
println replyString
changeWorkingDirectory('pub')
changeWorkingDirectory('books')
listFiles().each { file ->
if (file.type == FTPFile.FILE_TYPE) {
println "FILE: ${file.name}"
def incomingFile = new File(file.name)
incomingFile.withOutputStream { ostream ->
retrieveFile file.name, ostream
}
}
}
println "Me voy"
disconnect()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment