■■■

2016年4月5日火曜日

FtpWebRequestでFTPサーバー上のファイル更新日時を取得する方法

FtpWebRequestでFTPサーバー上のファイル更新日時を取得する方法
VB.NET
Dim u As New Uri("ftp://localhost/test.txt")

Dim ftpReq As System.Net.FtpWebRequest = _
CType(System.Net.WebRequest.Create(u), System.Net.FtpWebRequest)
ftpReq.Credentials = New System.Net.NetworkCredential("username", "password")
ftpReq.Method = System.Net.WebRequestMethods.Ftp.GetDateTimestamp

Dim ftpRes As System.Net.FtpWebResponse = _
CType(ftpReq.GetResponse(), System.Net.FtpWebResponse)
Console.WriteLine(ftpRes.LastModified)

Console.WriteLine("{0}: {1}", ftpRes.StatusCode, ftpRes.StatusDescription)
ftpRes.Close()
C#
Dim u As New Uri("ftp://localhost/test.txt")

Dim ftpReq As System.Net.FtpWebRequest = _
CType(System.Net.WebRequest.Create(u), System.Net.FtpWebRequest)
ftpReq.Credentials = New System.Net.NetworkCredential("username", "password")
ftpReq.Method = System.Net.WebRequestMethods.Ftp.GetDateTimestamp

Dim ftpRes As System.Net.FtpWebResponse = _
CType(ftpReq.GetResponse(), System.Net.FtpWebResponse)
Console.WriteLine(ftpRes.LastModified)

Console.WriteLine("{0}: {1}", ftpRes.StatusCode, ftpRes.StatusDescription)
ftpRes.Close()

■■■