Solved

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

Posted on 2002-03-29
11
340 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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 

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
 
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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 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