|
-
Oct 13th, 2005, 08:49 AM
#1
Thread Starter
Hyperactive Member
Check for file on FTP server...[RESOLVED]
Hey Everyone!
Long time no talk.
Basically, I need to (from VBA preferrably, but I can make a VB DLL) check for the existence of a $hitload of files on an FTP site. They're all in different folders and subfolders, but my code already knows all that.
I need a way to check to see if a file exists on an FTP site, without d/ling it. I've begun working with the MSINET.OCX control (Microsoft Internet Transfer Control 6.0 (SP6)) but I'm having connectivity issues with the FTP server and I don't think I can do a "FileExists" kind of thing anyways.
Any suggestions?
Thanks!
Added green "resolved" checkmark - Hack
Last edited by Hack; Oct 13th, 2005 at 12:02 PM.
-
Oct 13th, 2005, 09:07 AM
#2
Thread Starter
Hyperactive Member
Re: Check for file on FTP server...
Well,
Looks like I'm getting somewhere.
http://www.15seconds.com/issue/981203.htm
The above site is walking me through an acceptable solution. When I'm done I'll post my code for you guys to make fun of.
Thanks,
Ben
-
Oct 13th, 2005, 09:45 AM
#3
Thread Starter
Hyperactive Member
Re: Check for file on FTP server...
It aint fast, but it work:
Code:
Option Compare Database
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 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 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 InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Const MAX_PATH As Long = 255
Public Const FTPHost As String = "xxx"
Public Const FTPIP As String = "1.1.1.1"
Public Const FTPUser As String = "xxx"
Public Const FTPPass As String = "xxx"
Private Type FILETIME
dwLowDateTime As Long
dwHighDateTime As Long
End Type
Private Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As FILETIME
ftLastAccessTime As FILETIME
ftLastWriteTime As FILETIME
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type
Public Function FTPOpen() As Long
Dim hInternetOpen As Long
Dim hInternetConn As Long
hInternetOpen = InternetOpen("MedTel FTP Connection", 1, vbNullString, vbNullString, 0)
hInternetConn = InternetConnect(hInternetOpen, FTPHost, ftpport, FTPUser, FTPPass, 1, 0, 0)
FTPOpen = hInternetConn
End Function
Public Function FTPClose(lConn As Long) As Long
InternetCloseHandle lConn
End Function
Public Function FTPCheckForFile(strFileToFind As String) As String
Dim lConn As Long
Dim lResult As Long
Dim pData As WIN32_FIND_DATA
'init the filename buffer
pData.cFileName = String(260, 0)
lConn = FTPOpen
lResult = FtpFindFirstFile(lConn, strFileToFind, pData, 0, 0)
FTPClose lConn
FTPCheckForFile = lResult & "-" & pData.cFileName
End Function
Public Function FTPTestRun()
Debug.Print Now
Debug.Print FTPCheckForFile("medtel.werd.org/clients/wlavamc/Monthly_Reports/Extra_Questions/730_2005_09_EQ.zip")
Debug.Print FTPCheckForFile("medtel.werd.org/clients/wlavamc/Monthly_Reports/Extra_Questions/730_2005_08_EQ.zip")
Debug.Print FTPCheckForFile("medtel.werd.org/clients/wlavamc/Monthly_Reports/Extra_Questions/730_2005_07_EQ.zip")
Debug.Print FTPCheckForFile("medtel.werd.org/clients/wlavamc/Monthly_Reports/Extra_Questions/730_2005_06_EQ.zip")
Debug.Print FTPCheckForFile("medtel.werd.org/clients/wlavamc/Monthly_Reports/Extra_Questions/730_2005_05_EQ.zip")
Debug.Print Now
End Function
-Ben
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
|