FTP文件最后修改了VB.NET

时间:2015-07-23 08:09:26

标签: vb.net ftp datemodified

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

这是我到目前为止所做的:

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

之后我尝试了几行,但实际上都没有返回日期。

2 个答案:

答案 0 :(得分:2)

好吧我明白了,但是我会把它留在这里,因为我找不到任何关于此的其他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)

答案 1 :(得分:0)

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