Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

FTP Files

8 views
Skip to first unread message

Tom

unread,
Jun 22, 2003, 1:24:31 PM6/22/03
to
How can I programatically get the name of the files available for download from
a FTP site?

Thanks!

Tom


Richard Choate

unread,
Jun 22, 2003, 4:23:57 PM6/22/03
to
You should pick a newsgroup and post to it instead of posting this to all of
the groups. Posting to one place is more courteous to those people who try
to help you. For instance, this is not a "getting started" issue.

R Choate

"Tom" <tand...@verizon.net> wrote in message
news:jDlJa.7972$C83.7...@newsread1.prod.itd.earthlink.net...

Richard Choate

unread,
Jun 22, 2003, 4:21:45 PM6/22/03
to
It makes a difference how you approach it if the FTP site is a passworded
private site or if it is basically an open site like the Microsoft FTP
server. You can use the Microsoft INET control on a form to hook up with an
"easy" site, but I have personal experience with this thing and I know it
does not do well with more secure sites, or sites with passwords.

What type of target are you wanting the directory listing for? Also, this is
basically what you will get...a directory listing. You have to assume that
most of what is in the directory can be downloaded. Finally, you will find
that if you need to get a listing from a more challenging or passworded FTP
site, your best option is to use API calls to go get it.

Richard Choate, CPA

"Tom" <tand...@verizon.net> wrote in message
news:jDlJa.7972$C83.7...@newsread1.prod.itd.earthlink.net...

Tom

unread,
Jun 22, 2003, 4:59:10 PM6/22/03
to
Richard,

From the FAQ ---

4) Cross-posting is ok provided you include only the relevant newsgroups.

I frequent the three newsgroups I posted to on a daily basis. Not all users who
provide answers to posts frequent all three newsgroups. Some users on each
newsgroup have unique expertise. I fely my question was one that would take some
special expertise to answer and therefore I sought the expertise in the three
newsgroups. Cross posting to three newsgroups is not excessive! All you did was
greatly lower the probability to my getting an answer to my question by
interfering. My post now shows a response (not an answer) to my question and
therefore lowers the probability of someone opening my post and possibly
providing an answer.

Please keep your unfounded opinions to yourself the next time!!

Tom

"Richard Choate" <rchoa...@NoSpam.com> wrote in message
news:u15T2wPO...@TK2MSFTNGP10.phx.gbl...

Richard Choate

unread,
Jun 22, 2003, 7:09:41 PM6/22/03
to
Blow me. I did post a reponse on one of the NGs with some info about your
problem since this is a problem I have dealt with personally and
extensively. You did not need to post in all of the groups because they
weren't all relevant. I wasn't trying to be a jerk but you clearly are so
kiss my ass. Do your own research.

Richard

"Tom" <tand...@verizon.net> wrote in message

news:yMoJa.60434$Io.56...@newsread2.prod.itd.earthlink.net...

Richard Choate

unread,
Jun 22, 2003, 7:35:50 PM6/22/03
to
I apologize. I shouldn't have been so harsh. I guess I got mad because I
knew I was the only person who was actually trying to help you with a
response and you slammed me for commenting about the cross-post. I posted
your help in the Forms NG. If you need help with the API then I will give it
to you.
Richard

"Tom" <tand...@verizon.net> wrote in message

news:jDlJa.7972$C83.7...@newsread1.prod.itd.earthlink.net...

Tom

unread,
Jun 22, 2003, 8:11:18 PM6/22/03
to
Richard,

Apology accepted and thank you for being man enough to offer an apology. I
apologize to you too for blowing your comment out of proportion.

I would appreciate any help you can give me!

<<What type of target are you wanting the directory listing for? >>

I'm working on a database to process orders received on a webstore. The webstore
program creates a textfile for each order and places the textfile on an FTP
site. My database needs to go to the FTP site, look at the list of files there,
show the user which files have already been downloaded and allow the user to
download his choice of files. When files are downloaded, the names of the files
are stored in a table in the database and so the database needs to read the list
of the files on the FTP site, compare the list against those in the table that
have already been downloaded and then tell the user which ones have already been
downloaded. The user must enter a UserID and a Password to open the FTP site.

<<Also, this is basically what you will get...a directory listing. You have to
assume that most of what is in the directory can be downloaded. >>

All of what is in the directory will be downloadable. By directory listing I'm
presuming each file name can be compared against the list in the table of files
in the database described previously.

<<Finally, you will find that if you need to get a listing from a more
challenging or passworded FTP
site, your best option is to use API calls to go get it.>>

Sounds like I need to use the API calls. Please give me the details.

Sorry again for the outburst. I appreciate any help you can give me.

Tom

"Richard Choate" <rchoa...@NoSpam.com> wrote in message

news:OndMGcRO...@TK2MSFTNGP10.phx.gbl...

Richard Choate

unread,
Jun 22, 2003, 8:27:27 PM6/22/03
to
Hopefully, you can copy and paste these functions to a standard module. I
will post some more code in a second message in just a minute. This code
here is the set of calls that form the backbone of your FTP code:
Richard

Option Explicit
Public Const MAX_PATH = 260
Public Const INTERNET_FLAG_RELOAD = &H80000000
Public Const NO_ERROR = 0
Public Const FILE_ATTRIBUTE_READONLY = &H1
Public Const FILE_ATTRIBUTE_HIDDEN = &H2
Public Const FILE_ATTRIBUTE_SYSTEM = &H4
Public Const FILE_ATTRIBUTE_DIRECTORY = &H10
Public Const FILE_ATTRIBUTE_ARCHIVE = &H20
Public Const FILE_ATTRIBUTE_NORMAL = &H80
Public Const FILE_ATTRIBUTE_TEMPORARY = &H100
Public Const FILE_ATTRIBUTE_COMPRESSED = &H800
Public Const FILE_ATTRIBUTE_OFFLINE = &H1000
Public Const INTERNET_FLAG_PASSIVE = &H8000000
Public Const FORMAT_MESSAGE_FROM_HMODULE = &H800

Type WIN32_FIND_DATA
dwFileAttributes As Long
ftCreationTime As Currency
ftLastAccessTime As Currency
ftLastWriteTime As Currency
nFileSizeHigh As Long
nFileSizeLow As Long
dwReserved0 As Long
dwReserved1 As Long
cFileName As String * MAX_PATH
cAlternate As String * 14
End Type


Public Const ERROR_NO_MORE_FILES = 18

Public Declare Function InternetFindNextFile Lib "wininet.dll" Alias
"InternetFindNextFileA" _
(ByVal hFind As Long, lpvFindData As WIN32_FIND_DATA) As Long

Public 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

Declare Function FileTimeToLocalFileTime Lib "kernel32" (lpFileTime As Any,
lpLocalFileTime As Any) As Long

Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_INVALID_PORT_NUMBER = 0
Public Const INTERNET_SERVICE_FTP = 1
Public Const FTP_TRANSFER_TYPE_BINARY = &H2
Public Const FTP_TRANSFER_TYPE_ASCII = &H1

Public Declare Function FtpSetCurrentDirectory Lib "wininet.dll" Alias
"FtpSetCurrentDirectoryA" _
(ByVal hFtpSession As Long, ByVal lpszDirectory As String) As Boolean

Public Declare Function FtpGetCurrentDirectory Lib "wininet.dll" Alias
"FtpGetCurrentDirectoryA" _
(ByVal hFtpSession As Long, ByVal lpszCurrentDirectory As String,
lpdwCurrentDirectory As Long) As Boolean

Public Declare Function InternetWriteFile Lib "wininet.dll" _
(ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long,
_
dwNumberOfBytesWritten As Long) As Integer

Public Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" _
(ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long,
ByVal Flags As Long, ByVal Context As Long) As Long

Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" _
(ByVal hFtpSession As Long, ByVal lpszLocalFile As String, _
ByVal lpszRemoteFile As String, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean


Public Declare Function FtpDeleteFile Lib "wininet.dll" _
Alias "FtpDeleteFileA" (ByVal hFtpSession As Long, _
ByVal lpszFileName As String) As Boolean
Public Declare Function InternetCloseHandle Lib "wininet.dll" _
(ByVal hInet As Long) As Long

Public 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

Public 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


Public Declare Function FtpGetFile Lib "wininet.dll" Alias "FtpGetFileA" _
(ByVal hFtpSession As Long, ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, ByVal fFailIfExists As Boolean, ByVal
dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, ByVal dwContext As Long) As Boolean


Const rDayZeroBias As Double = 109205# ' Abs(CDbl(#01-01-1601#))
Const rMillisecondPerDay As Double = 10000000# * 60# * 60# * 24# / 10000#

Declare Function InternetGetLastResponseInfo Lib "wininet.dll" _
Alias "InternetGetLastResponseInfoA" _
(ByRef lpdwError As Long, _
ByVal lpszErrorBuffer As String, _
ByRef lpdwErrorBufferLength As Long) As Boolean

Declare Function FormatMessage Lib "kernel32" Alias "FormatMessageA" _
(ByVal dwFlags As Long, ByVal lpSource As Long, ByVal dwMessageId As Long, _
ByVal dwLanguageId As Long, ByVal lpBuffer As String, ByVal nSize As Long,
_
Arguments As Long) As Long

Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA"
(ByVal lpLibFileName As String) As Long


Function Win32ToVbTime(ft As Currency) As Date

Dim ftl As Currency

' Call API to convert from UTC time to local time
If FileTimeToLocalFileTime(ft, ftl) Then

' Local time is nanoseconds since 01-01-1601

' In Currency that comes out as milliseconds

' Divide by milliseconds per day to get days since 1601

' Subtract days from 1601 to 1899 to get VB Date equivalent

Win32ToVbTime = CDate((ftl / rMillisecondPerDay) - rDayZeroBias)

Else

MsgBox Err.LastDllError

End If

End Function


Richard Choate

unread,
Jun 22, 2003, 8:35:00 PM6/22/03
to
You know what, this will make much more sense to you if I can send you a
database file with a form and all the code needed to do what you want to do.
Then you could adjust it to suit your needs. There is just a lot of code.
Do you want me to send it to the address shown within this message?
Richard

"Tom" <tand...@verizon.net> wrote in message

news:GArJa.8448$C83.8...@newsread1.prod.itd.earthlink.net...

Richard Choate

unread,
Jun 22, 2003, 9:15:53 PM6/22/03
to
Do you still need the rest of my code or have you solved your problem by
other means already?
Richard

"Tom" <tand...@verizon.net> wrote in message
news:jDlJa.7972$C83.7...@newsread1.prod.itd.earthlink.net...

Dan Artuso

unread,
Jun 22, 2003, 9:22:44 PM6/22/03
to
Hi,
Here you go:
http://www.mvps.org/vbnet/code/internet/ftplist.htm

This is for Visual basic but can be used in Access.
The code will allow you to connect to an ftp site and obtain
a file listing.

--
HTH
Dan Artuso, MVP

"a problem well stated is a problem half solved"


"Tom" <tand...@verizon.net> wrote in message

news:GArJa.8448$C83.8...@newsread1.prod.itd.earthlink.net...

Richard Choate

unread,
Jun 22, 2003, 9:39:36 PM6/22/03
to
That is a good resource with similar code to mine, but mine is already
written for Access with a sample Access form.
Richard

"Dan Artuso" <dar...@NOSPAMpagepearls.com> wrote in message
news:OwIWmaSO...@TK2MSFTNGP10.phx.gbl...

Kristine

unread,
Jun 22, 2003, 10:42:44 PM6/22/03
to
I appreciate your offer to send me your database file with a form and all the
code needed to get a directory listing from a FTP site. Yes, send it to
rla...@penn.com.

Tom

"Richard Choate" <rchoa...@NoSpam.com> wrote in message

news:eoTr#TSODH...@TK2MSFTNGP10.phx.gbl...

Kristine

unread,
Jun 22, 2003, 10:43:30 PM6/22/03
to
To be sure you get this message ---

I appreciate your offer to send me your database file with a form and all the
code needed to get a directory listing from a FTP site. Yes, send it to
rla...@penn.com.

Tom


"Richard Choate" <rchoa...@NoSpam.com> wrote in message

news:#Pipu9RO...@TK2MSFTNGP12.phx.gbl...

Kristine

unread,
Jun 22, 2003, 10:44:02 PM6/22/03
to
Thanks, Dan!

Tom


"Dan Artuso" <dar...@NOSPAMpagepearls.com> wrote in message
news:OwIWmaSO...@TK2MSFTNGP10.phx.gbl...

0 new messages