Solved

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

Posted on 2002-03-29
11
337 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

895 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

13 Experts available now in Live!

Get 1:1 Help Now