【发布时间】:2020-11-11 17:53:27
【问题描述】:
我想获取远程文件的创建日期,但我没有找到提供此选项的方法。 我只能得到最后修改日期,但我想得到这个文件的创建日期:
这是我的代码:
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class mytest {
public static void main(String args[]) throws ParseException {
//===============================================================
String hostname = "10.10.11.19";
String username = "root";
String password = "passwword";
String remoteFile = "/opt/test_pyt/teeeeeeest.txt"
String copyTo = "/home/desk/Desktop";
JSch jsch = new JSch();
Session session = null;
System.out.println("Trying to connect.....");
try {
session = jsch.getSession(username, hostname, 22);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
//get date of file=========================================
String lastModif = sftpChannel.lstat(remoteFile).getMtimeString();
//I want to get creation date =============================
creation_date= ???????????;
//==============================================
sftpChannel.get(remoteFile, copyTo);
sftpChannel.exit();
session.disconnect();
} catch (JSchException e) {
} catch (SftpException e) {
}
}
}
谢谢
【问题讨论】:
-
并非所有文件系统都会记录文件的创建时间。可能没有价值。