• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Wininet--- FtpGet alters date to Current date time.

I am using Wininet to get files from a server.
I need to know the original Date and Time of the the file i am getting from the server.

If i use  Ftpget

  x = FtpGetFile(hconnection1, _
                        SremoteFile, _
                        SnewFile, _
                        False, _
                        FILE_ATTRIBUTE_ARCHIVE, _
                        FTP_TRANSFER_TYPE_ASCII, _
                        0&)

The file date and time is altered to current data and time.
eg. if i use filedatetime(snewfile)
or scripting.     f.datecreated

????  1. Can ftpget be told to leave the date alone??
      2. Is there a way of 1st looking at the file on the server, getting the data , time, and then altering the date/time on the file received.


Appreciate any help.


0
kennedymr
Asked:
kennedymr
  • 6
  • 5
1 Solution
 
Richie_SimonettiIT OperationsCommented:
Yes it is possible with you are already saying.
File date an time is altered but only in lastaccess member of WIN32_FIND_DATA.
0
 
Richie_SimonettiIT OperationsCommented:
I have been using this code to get all specs from files in a drive, you could use it replacin findfirstfile,findnext and findclose with respective API for internet (FtpFindFirstFile and so on)

Private Sub cmdGetFiles_Click()
Const SHGFI_TYPENAME = &H400
Const SHGFI_DISPLAYNAME = &H200
Dim fiTmp As String
Dim FI As SHFILEINFO

Dim HFile As Long
Dim FindData As WIN32_FIND_DATA
Dim FTime As FILETIME
Dim STime As SYSTEMTIME

Dim sFilename As String, SFullPath As String
Dim idx As Long, lRet As Long
Dim lstItem As ListItem
Dim ff As New clsFFile
Set ffiles = New colFFiles
SFullPath = CreatePath(txtNames(0).Text, txtNames(1).Text)
HFile = FindFirstFile(SFullPath, FindData)
LV.ListItems.Clear
Do
    sFilename = StripNull(FindData.cFileName)
    If (sFilename <> ".." And sFilename <> ".") Then
        Set ff = ffiles.Add(sFilename)
        With ff
            .FileSize = FindData.nFileSizeLow
            .ShortName = StripNull(FindData.cAlternate)
            .LongName = sFilename
'            .DateAccessed = CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
            FileTimeToSystemTime FindData.ftCreationTime, STime
            .DateCreated = CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
            FileTimeToSystemTime FindData.ftLastWriteTime, STime
            .DateModified = CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
            FileTimeToSystemTime FindData.ftLastAccessTime, STime
            .DateAccessed = CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
            fiTmp = Left$(SFullPath, InStrRev(SFullPath, "\", , vbTextCompare)) & .LongName
            SHGetFileInfo fiTmp, 0, FI, Len(FI), SHGFI_DISPLAYNAME Or SHGFI_TYPENAME
            .FileType = StripNull(FI.szTypeName)
            ' populate list
            Set lstItem = LV.ListItems.Add(, , .LongName)
            lstItem.ListSubItems.Add , , .FileSize
            lstItem.ListSubItems.Add , , .DateCreated
            lstItem.ListSubItems.Add , , .DateAccessed
            lstItem.ListSubItems.Add , , .DateModified
            lstItem.ListSubItems.Add , , .FileType
            Label1(2).Caption = "listing... " & .LongName
            Label1(2).Refresh
        End With
    End If
    lRet = FindNextFile(HFile, FindData)
    If lRet = 0 Then Exit Do
Loop
FindClose HFile
Label1(2).Caption = "Done"
End Sub




0
 
Richie_SimonettiIT OperationsCommented:
Also, i have an example and a class to manage ftp stuff.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
kennedymrAuthor Commented:
From: Richie_Simonetti
Appreciate your example, but it seems to be only for the local drive.
I need to get the info from a file on an ftp server, prior to downloading.
Your example uses only findfirstfile...
I am needing to use ftpfindfirstfile,
------------------------------------
I have reached this far....
 
Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
   hFind = FtpFindFirstFile(hconnection1, "\xxx\aaaaaa.111", pData, 0, 0)
   
    MsgBox (pData.cFileName)

-----------up to here ok......
But... not working

MsgBox (pData.ftCreationTime)


Appreciate any help
0
 
kennedymrAuthor Commented:
Basically what i am trying to do is..

Look at an FTP Site for a Particular File, and get the Date and Time of the file.

use FTpgetfile to get the file.,which seems to put the current date/time of my machine on it.

Then,,, alter the date back to the date it was on the server.
 
0
 
Richie_SimonettiIT OperationsCommented:
So i did, check my comments too!
You need to replace findfirstfile, findnextfile and find close with ftpfindfirstfile,internetfindnextfile and InternetCloseHandle....

This is what i have and use:

Public Function EnumFilesFTP(ByRef lcount As Long, Optional ByVal sExtension As String = "*.*", Optional lview As Control) As String()

Dim arrFiles() As String, idx As Long
Dim pData As WIN32_FIND_DATA, hFind As Long, lRet As Long
Dim FTime As FILETIME
Dim STime As SYSTEMTIME
Dim lstItem  As Object
'create a buffer
pData.cFileName = String(MAX_PATH, 0)
   
'find the first file
hFind = FtpFindFirstFile(m_InetConnect, sExtension, pData, 0, 0)
   
Do While hFind <> 0
   
    'show the filename
    Dim FName As String
    FName = StripNull(pData.cFileName)
    If FName <> "." And FName <> ".." Then
       idx = idx + 1
       ReDim arrFiles(idx)
       arrFiles(idx) = FName
       If Not lview Is Nothing Then
           Set lstItem = lview.ListItems.Add(, , FName)
           With lstItem.ListSubItems
            .Add , , pData.nFileSizeLow
            FileTimeToSystemTime pData.ftCreationTime, STime
            .Add , , CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
            FileTimeToSystemTime pData.ftLastWriteTime, STime
            .Add , , CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
            FileTimeToSystemTime pData.ftLastAccessTime, STime
            .Add , , CDate(STime.wDay & "/" & STime.wMonth & "/" & STime.wYear)
           End With
       End If
       'find the next file
       lRet = InternetFindNextFile(hFind, pData)
       'if there's no next file, exit do
       If lRet = 0 Then Exit Do
       'show the filename
    End If
Loop
   
'close the search handle
InternetCloseHandle hFind
'returns names of files found and quantity
lcount = idx
EnumFilesFTP = arrFiles
End Function

0
 
kennedymrAuthor Commented:
Appreciate your help, i now have it all working.

regards  kennedymr
0
 
kennedymrAuthor Commented:

I did not notice..  The above routine gives the Date ok,
???How do i get the Time  eg 16:30:22
0
 
kennedymrAuthor Commented:
Hvae worked it out   BUT  
FileTimeToSystemTime pData.ftLastWriteTime, STime
MsgBox ((STime.wSecond))

MsgBox (Format(STime.wHour, "####") & ":" & Format(STime.wMinute, "####") & ":" & Format(STime.wSecond, "####"))


Allways gives 0  as the seconds.

Is there any way to get the seconds???
0
 
Richie_SimonettiIT OperationsCommented:
Good question, i didn't try it since i didn't need time!
Not all server retrieves date values so, maybe, not time also.


0
 
kennedymrAuthor Commented:
Thanks for your help..  signing off !!!!
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 6
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now