Solved

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

Posted on 2002-03-29
11
336 Views
Last Modified: 2012-06-27
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
Comment
Question by:kennedymr
  • 6
  • 5
11 Comments
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6906413
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6906423
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6906486
Also, i have an example and a class to manage ftp stuff.
0
 

Author Comment

by:kennedymr
ID: 6906554
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
 

Author Comment

by:kennedymr
ID: 6906713
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 16

Accepted Solution

by:
Richie_Simonetti earned 50 total points
ID: 6907736
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
 

Author Comment

by:kennedymr
ID: 6907803
Appreciate your help, i now have it all working.

regards  kennedymr
0
 

Author Comment

by:kennedymr
ID: 6907815

I did not notice..  The above routine gives the Date ok,
???How do i get the Time  eg 16:30:22
0
 

Author Comment

by:kennedymr
ID: 6907904
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6908210
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
 

Author Comment

by:kennedymr
ID: 6908450
Thanks for your help..  signing off !!!!
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now