http://commons.apache.org/net/download_net.cgi
從上面的網站上下載,FTP所要用到的包。
代碼如下:
import org.apache.commons.net.ftp.FTPClient
.......
void upFile(){
def config = new ConfigSlurper("configure").parse(new File('Configure.groovy').toURL())
def ftpClient = new FTPClient()
///下面是從配置文件中加載的FTP信息,并且通過解密得到,加解密,在groovy實踐中有。
ftpClient.setDefaultPort(Integer.parseInt (DESCodec.decode("${config.ftp.ftpPort}")));
ftpClient.connect(DESCodec.decode("${config.ftp.ftpIp}"))
ftpClient.enterLocalPassiveMode()
ftpClient.login(DESCodec.decode("${config.ftp.ftpUser}"), DESCodec.decode("${config.ftp.ftpPw}"))
// println ftpClient.getReplyString()
ftpClient.changeWorkingDirectory("/asdtiang")
ftpClient.fileType=(FTPClient.BINARY_FILE_TYPE)
def upFile = new File("record.txt")
upFile.withInputStream { ostream ->
ftpClient.storeFile(new Date().format("yyyy-MM-dd")+'.txt', ostream )
}
// println ftpClient.getReplyString()
ftpClient.disconnect()
// upFile.write("") 主要是為了清空文件,
}
def config = new ConfigSlurper("configure").parse(new File('Configure.groovy').toURL())
def ftpClient = new FTPClient()
///下面是從配置文件中加載的FTP信息,并且通過解密得到,加解密,在groovy實踐中有。
ftpClient.setDefaultPort(Integer.parseInt (DESCodec.decode("${config.ftp.ftpPort}")));
ftpClient.connect(DESCodec.decode("${config.ftp.ftpIp}"))
ftpClient.enterLocalPassiveMode()
ftpClient.login(DESCodec.decode("${config.ftp.ftpUser}"), DESCodec.decode("${config.ftp.ftpPw}"))
// println ftpClient.getReplyString()
ftpClient.changeWorkingDirectory("/asdtiang")
ftpClient.fileType=(FTPClient.BINARY_FILE_TYPE)
def upFile = new File("record.txt")
upFile.withInputStream { ostream ->
ftpClient.storeFile(new Date().format("yyyy-MM-dd")+'.txt', ostream )
}
// println ftpClient.getReplyString()
ftpClient.disconnect()
// upFile.write("") 主要是為了清空文件,
}
天蒼蒼,野茫茫,風吹草底見牛羊