大家好,
我试图测试输入文件是否存在于FTP服务器中。如果文件存在,我想显示文件存在。如果没有,则显示文件未找到消息。
see the below code once
import org.apache.commons.net.ftp.FTPClient
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPFile;
import java.text.SimpleDateFormat;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.DateFormat
import groovy.io.FileType
start()
def start(){
def ftpClient = new FTPClient()
ftpClient.connect(server)
ftpClient.login(user,pass)
ftpClient.enterLocalPassiveMode()
FTPFile[] f= ftpClient.listFiles("/Autoplus.txt");
for(FTPFile ff : f){
if(ff.exists()){
return "File existed"
}
else{
return "File not found!"
}
}
}
如果有任何错误,请执行上述操作
由于
答案 0 :(得分:0)
def filePath = "/tmp/file.json"
def file = new File(filePath)
assert file.exists() : "file found"