FTP 文件上次修改 VB.NET

FTP file last modified VB.NET

如何在 Visual Basic 中从 FTP 服务器上的文件获取修改日期?

这是我目前拥有的:

Dim request = CType(WebRequest.Create(URL + ZipFile), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.GetDateTimestamp

之后我尝试了几行,但 none 实际上 return 日期。

好吧,我想出来了,但我会把它留在这里,因为我找不到任何其他 vb.net 帖子:

Imports System.Net
Imports System.Globalization

Dim request = CType(WebRequest.Create(URL + ZipFile), FtpWebRequest)
request.Method = WebRequestMethods.Ftp.GetDateTimestamp
Dim response = CType(request.GetResponse(), FtpWebResponse)
Dim ServerDate = DateTime.ParseExact(response.StatusDescription.Substring(4,14),"yyyyMMddHHmmss",_
                                     Cultureinfo.InvariantCulture,DateTimeStyles.None)
Private Function ServerDateFile(FtpFullPathFile) As Date
        Dim request As FtpWebRequest = WebRequest.Create(FtpFullPathFile)
        request.Credentials = New NetworkCredential( YourFtpUserName, YourPassWord)
        request.Method = WebRequestMethods.Ftp.GetDateTimestamp

        Dim dLastModified As Date = Date.MinValue 'Change for your default value or nothing

        Try
            Using response As FtpWebResponse = request.GetResponse()
                dLastModified = response.LastModified                   
            End Using
        Catch ex As WebException
            MsgBox(ex.Message, vbCritical)
        End Try

        Return dLastModified
    End Function