>Hi All,
>
>I'm trying to set a list of *.csv files from a FTP server so that I can download them and then remove them from the server. The issue is that I don't know the names of the files, they start with Orderxxxxxxx.csv so need to get a list into an array and then get them one by one. However I'm trying aFtpDir from wwftp and also FtpFindFirstFile directly but I'm having no joy. I've tried looking for *.* and other variations but I'm not getting any list back. tried a few searches but can't see a solution, any help appreciated.
>
>~M
Isn't there another problem that might be related to your access to the server or to the FTP folders?...
Anyway, a self-contained working piece of code to fetch a list of files that match a particular filename match (no error handling)
DECLARE INTEGER InternetOpen in WinINet.dll ;
STRING Agent, INTEGER Type, STRING Proxy, STRING Bypass, INTEGER Flags
DECLARE INTEGER InternetCloseHandle in WinINet.dll ;
INTEGER InternetHandle
DECLARE INTEGER InternetConnect in WinINet.dll ;
INTEGER InternetSession, STRING Server, INTEGER Port, ;
STRING UserName, STRING Password, INTEGER Service, INTEGER Flags, INTEGER Context
DECLARE INTEGER FtpSetCurrentDirectory IN WinINet.dll ;
INTEGER FtpSession, STRING Directory
DECLARE INTEGER FtpFindFirstFile IN WinINet.dll ;
INTEGER FtpSession, STRING FilePattern, STRING @ FindData, INTEGER Flags, ;
INTEGER Context
DECLARE INTEGER InternetFindNextFile IN WinINet.dll ;
INTEGER FtpDir, STRING @ FindData
LOCAL Server AS String
LOCAL Port AS Integer
LOCAL UserName AS String
LOCAL Password AS String
LOCAL RemoteDir AS String
LOCAL FilePattern AS String
LOCAL FileData AS String
LOCAL ARRAY RemoteFiles(1)
m.Server = "yourserver"
m.Port = 21
m.UserName = "login"
m.Password = "password"
m.RemoteDir = "/public"
m.FilePattern = "Order*.csv"
m.FileData = REPLICATE(CHR(0),318)
LOCAL NetSession AS Integer
LOCAL FTPSession AS Integer
LOCAL FTPDir AS Integer
m.NetSession = InternetOpen("Wininet",0,.NULL.,.NULL.,0)
IF m.NetSession != 0
m.FTPSession = InternetConnect(m.NetSession,m.Server,m.Port,m.UserName,m.Password,1,0x08000000,0)
IF m.FTPSession != 0
IF FtpSetCurrentDirectory(m.FTPSession,m.RemoteDir) != 0
m.FTPDir = FtpFindFirstFile(m.FTPSession,m.FilePattern,@m.FileData,0,0)
IF m.FTPDir != 0
DIMENSION m.RemoteFiles(1)
m.RemoteFiles[1] = STREXTRACT(SUBSTR(m.FileData,45,260),"",CHR(0),1,2)
m.FileData = REPLICATE(CHR(0),318)
DO WHILE InternetFindNextFile(m.FTPDir, @m.FileData) != 0
DIMENSION m.RemoteFiles(ALEN(m.RemoteFiles) + 1)
m.RemoteFiles[ALEN(m.RemoteFiles)] = STREXTRACT(SUBSTR(m.FileData,45,260),"",CHR(0),1,2)
m.FileData = REPLICATE(CHR(0),318)
ENDDO
InternetCloseHandle(m.FTPDir)
ENDIF
ENDIF
InternetCloseHandle(m.FTPSession)
ENDIF
InternetCloseHandle(m.NetSession)
ENDIF
----------------------------------
António Tavares Lopes