|
-
August 25th, 2001, 06:57 PM
#1
GetFileTime on Remove machine
Trying to get the creation time of a file on a remove machine. I can ftp to the machine using wininet and get a listing of the files but what I also want to do is to get the creation date. I've tried the GetFileTime function,which works on a local file but not a remote file, FileTimeToSystemTime Here's a sample of the code
First the declare functions
private Declare Function InternetCloseHandle Lib "wininet.dll" (byval hInet as Long) as Integer
private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (byval hInternetSession as Long, byval sServerName as string, byval nServerPort as Integer, byval sUserName as string, byval sPassword as string, byval lService as Long, byval lFlags as Long, byval lContext as Long) as Long
private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (byval sAgent as string, byval lAccessType as Long, byval sProxyName as string, byval sProxyBypass as string, byval lFlags as Long) as Long
private Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias "FtpSetCurrentDirectoryA" (byval hFtpSession as Long, byval lpszDirectory as string) as Boolean
private Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias "FtpGetCurrentDirectoryA" (byval hFtpSession as Long, byval lpszCurrentDirectory as string, lpdwCurrentDirectory as Long) as Long
private Declare Function FtpCreateDirectory Lib "wininet.dll" Alias "FtpCreateDirectoryA" (byval hFtpSession as Long, byval lpszDirectory as string) as Boolean
private Declare Function FtpRemoveDirectory Lib "wininet.dll" Alias "FtpRemoveDirectoryA" (byval hFtpSession as Long, byval lpszDirectory as string) as Boolean
private Declare Function FtpDeleteFile Lib "wininet.dll" Alias "FtpDeleteFileA" (byval hFtpSession as Long, byval lpszFileName as string) as Boolean
private Declare Function FtpRenameFile Lib "wininet.dll" Alias "FtpRenameFileA" (byval hFtpSession as Long, byval lpszExisting as string, byval lpszNew as string) as Boolean
private Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" (byval hConnect as Long, byval lpszRemoteFile as string, byval lpszNewFile as string, byval fFailIfExists as Long, byval dwFlagsAndAttributes as Long, byval dwFlags as Long, byref dwContext as Long) as Boolean
private Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (byval hConnect as Long, byval lpszLocalFile as string, byval lpszNewRemoteFile as string, byval dwFlags as Long, byval dwContext as Long) as Boolean
private Declare Function InternetGetLastResponseInfo Lib "wininet.dll" Alias "InternetGetLastResponseInfoA" (lpdwError as Long, byval lpszBuffer as string, lpdwBufferLength as Long) as Boolean
private Declare Function FtpFindFirstFile Lib "wininet.dll" Alias "FtpFindFirstFileA" (byval hFtpSession as Long, byval lpszSearchFile as string, lpFindFileData as WIN32_FIND_DATA, byval dwFlags as Long, byval dwContent as Long) as Long
private Declare Function InternetFindNextFile Lib "wininet.dll" Alias "InternetFindNextFileA" (byval hFind as Long, lpvFindData as WIN32_FIND_DATA) as Long
private Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime as FILETIME, lpSystemTime as SystemTime) as Long
private Declare Function GetFileTime Lib "kernel32" (byval hfile as Long, lpCreationTime as FILETIME, lpLastAccessTime as FILETIME, lpLastWriteTime as FILETIME) as Long
private Declare Function OpenFile Lib "kernel32" (byval lpFileName as string, lpReOpenBuff as OFSTRUCT, byval wStyle as Long) as Long
private Declare Function hread Lib "kernel32" Alias "_hread" (byval hfile as Long, lpBuffer as Any, byval lBytes as Long) as Long
private Declare Function lclose Lib "kernel32" Alias "_lclose" (byval hfile as Long) as Long
Here's the sub
public Sub EnumFiles(hConnection as Long)
Dim pData as WIN32_FIND_DATA
Dim hFind as Long
Dim lRet as Long
Dim gfile as string
Dim hfile as Integer
Dim CreationTime as FILETIME
Dim LastAccessTime as FILETIME
Dim LastWriteTime as FILETIME
Dim SystemTime as SystemTime
Dim FileStruct as OFSTRUCT
Dim iRC as Integer
'set the graphics mode to persistent
me.AutoRedraw = true
'create a buffer
pData.cFileName = string(MAX_PATH, 0)
'find the first file
hFind = FtpFindFirstFile(hConnection, "*.*", pData, 0, 0)
'if there's no file, then exit sub
If hFind = 0 then Exit Sub
gfile = Left(pData.cFileName, InStr(1, pData.cFileName, string(1, 0), vbBinaryCompare) - 1)
'me.lstSDirList.AddItem gfile
'Debug.print gfile
Do
If gfile = "." Or gfile = ".." then
lRet = InternetFindNextFile(hFind, pData)
gfile = Left(pData.cFileName, InStr(1, pData.cFileName, string(1, 0), vbBinaryCompare) - 1)
else
me.lstSDirList.AddItem gfile
'create a buffer
pData.cFileName = string(MAX_PATH, 0)
'find the next file
hfile = OpenFile(gfile, FileStruct, OF_READ Or OF_SHARE_DENY_NONE) 'THIS SHOULD EQUAL > 0 BUT I get -1
If hfile = 0 then
MsgBox "Can't open the file", vbExclamation
Exit Sub
End If
If GetFileTime(hfile, CreationTime, LastAccessTime, LastWriteTime) then
' massage time into format that we can use
If Not FileTimeToSystemTime(LastAccessTime, SystemTime) then
print "Year of file :" & SystemTime.wYear
print "Month of File :" & SystemTime.wMonth
print "Day of File :" & SystemTime.wDay
else
MsgBox "FileTimeToSystemTime Failed"
End If
else
'MsgBox "GetFileTime Failed"
End If
iRC = lclose(hfile)
lRet = InternetFindNextFile(hFind, pData)
gfile = Left(pData.cFileName, InStr(1, pData.cFileName, string(1, 0), vbBinaryCompare) - 1)
'if there's no next file, exit do
If lRet = 0 then
Exit Do
End If
Debug.print gfile
End If
Loop
'close the search handle
InternetCloseHandle hFind
End Sub
Am I missing something.
-
August 26th, 2001, 08:49 AM
#2
Re: GetFileTime on Remove machine
U can open only files on your machine or files in shared space (if U have the parmission). A file in a FTP site isn't shared with U! U must ask to remote FTP service to open it for U.... better U must ask to remote FTP service the creation date of file.
an examle of this...
open dos propmt and with ftp.exe connect to the FTP site. now U type ls -la. U have a list of files and some information about them... but U can't open them!! U must GETTING before!
hi,brt
<center>
<HR width=80%>
<img src='http://web.tiscali.it/bertaplanet/im...ertaplanet.gif'>
</center>
-
August 26th, 2001, 11:20 AM
#3
Re: GetFileTime on Remove machine
Then is there any way to get the creation time of the file on a remote machine once I use InternetConnect to connect to the remote machine. I want to find all files on a remote machine that is more than 2 weeks old.
-
August 28th, 2001, 01:04 PM
#4
Re: GetFileTime on Remove machine
If you read the docs carefully you'll notice that not all filesystems support CreationTime, LastAccessTime, and LastWriteTime... I think if you look at LastWriteTime instead of CreationTime you'll have some luck....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|