我试图将本地文件夹文件的 lastmodifieddate 设置为 FTP 文件的 lastmodifieddate。但是,在返回值中它返回 false 并且日期也没有正确设置。
这是功能,
public static void getModifiedDateAndTimeFromFTPFile(String FTPHost, String FTPUserName, String FTPPassword, String FTPRemoteDirectory, String localFilePath, String fileName) {
try{
//get Local File
File fileLocal = new File(localFilePath + fileName);
//Connect to FTP and get the lastmodified time of File.
FTPClient client = new FTPClient();
client.connect(FTPHost);
client.login(FTPUserName, FTPPassword);
client.changeWorkingDirectory(FTPRemoteDirectory);
FTPFile ftpFile = client.listFiles(fileName)[0];
//Get last_modified date of FTP file.
Date ftpFileDate = ftpFile.getTimestamp().getTime();
//Now set date to the Local File.
boolean boolSetTime = fileLocal.setLastModified(ftpFileDate.getTime());
System.out.println(" Was last modified time set successfully ? : " + boolSetTime);
} catch (Exception ex) {
System.out.println("Error : " + ex.toString());
}
}
任何人都可以通过指出我的错误来帮助我吗?
谢谢