Results 1 to 3 of 3

Thread: Get current date from HTTP or FTP sever?

  1. #1
    Super_Collector is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2008
    Posts
    7
    Reputation
    0

    Get current date from HTTP or FTP sever?

    Hello... This is hopefully a super simple question on an advanced topic.

    I have a leased VPS, so I have any kind of access I need to it. I am writing an application in Visual Basic 2005 and all I want to do is make some sort of call out to the web or ftp server to ask what the current server date is. (I want to compare it to the local computer date to make sure they are in agreement.)

    Is anybody available to help me with my Saturday morning problem? Spent my Friday night trying to make different API calls out to WebBrowser1 and trap the results (unsuccessfully). Surely there has got to be a cleaner / easier way.

    Thank you in advance for any helpful direction.

    -Geoffrey
    Last edited by Super_Collector; 05-12-2012 at 10:51 PM.

  2. #2
    Super_Collector is offline VB.NET Forum Newbie
    .NET Framework
    .NET 3.5 (VS 2008)
    Join Date
    Aug 2008
    Posts
    7
    Reputation
    0

    Resolved: Get Date From Web Server

    Got it.

    First I wrote sync.php and uploaded it to my server:
    HTML Code:
    <?php;$today = date("m-d-y");Print $today;?>
    Then I pointed my not-visible webbrowser1 at the URL with sync.php and read result with WebBrowser1.Document.Body.InnerText

    I found a lot of baffling (to a beginner) answers on the web about reading the date value from http headers, but in the end simplicity won the day.

    Too bad it took two days to think it up.

    -Geoffrey

  3. #3
    JohnH's Avatar
    JohnH is offline VB.NET Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Dec 2005
    Location
    Norway
    Posts
    14,204
    Reputation
    2369
    Reading the date value from Http headers is not very complicated:
            Dim request = Net.WebRequest.Create("http://server")
    request.Method = Net.WebRequestMethods.Http.Head
    Dim response = request.GetResponse
    response.Close()
    Dim utc = Date.Parse(response.Headers("Date"))
    Dim local = utc.ToLocalTime

    It is not possible with Ftp protocol. (you can find suggestions to upload an empty file, check its date stamp, then delete it)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Harvest time tracking