![](/img/trans.png)
[英]Upload file uploaded via HTTP to ASP.NET further to FTP server in C#
[英]Get upload time of file uploaded at ftp server
誰能告訴我從FTP服務器上載文件的時間?
class listFiles
{
public static void Main(string[] args)
{
listFiles l = new listFiles();
l.getFileList(ftpConnection,"test123","pass123"); //ftp url
}
private void getFileList(string FTPAddress, string username, string password)
{
List<string> files = new List<string>();
try
{
//Create FTP request
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(FTPAddress);
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
while (!reader.EndOfStream)
{
//Application.DoEvents();
// string fileType = reader.ReadLine();
files.Add(reader.ReadLine());
}
//Clean-up
reader.Close();
responseStream.Close(); //redundant
response.Close();
}
catch (Exception)
{
Console.WriteLine("There was an error connecting to the FTP Server");
}
//If the list was successfully received, display it to the user
//through a dialog
if (files.Count != 0)
{
foreach (string file in files)
{
Console.WriteLine(file);
}
}
}
嘗試使用FtpWebResponse.LastModified
屬性
using (FtpWebResponse resp = (FtpWebResponse)request.GetResponse())
{
var lastModified = resp.LastModified ;
}
您需要獲取每個文件的響應,在當前代碼中您已經具有文件列表,通過使用該文件名建立ftp文件的完整路徑,您需要找到創建日期。 之后,創建到該完整ftp文件路徑的ftp請求。 那么您可以讀取響應對象的最后修改日期。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.