the code now uses functions, you can use either ALLOC / MEMBLOCK (GET MEMBLOCK PTR) / BANK (GET BANK PTR) or DIM and then obtain the array pointer using GET ARRAYPTR. you need IanM Matrix1Util plugin for this.
Change the code if you want, make it better. I'm going to be updating the DBPRO source code to fix some of the commands that don't work. I've already noticed in the source code that the code is wrong for GET FTP DIR$(). This is easily fixed.
A few months back I updated the memblocks source code to allow more memblocks, If I recall I added 10,000 as a tester and compiles / works fine so far. There is so much that can be done with the source code. I've seen quite a lot of mistakes in places and/or inconsistencies, memory leaks etc.
I haven't put the dll calls to close the handles in yet, maybe you guys/girls can have a go. But I will add later date. Im off to do working day and then update DBPro code etc.
sync on : sync rate 30 : sync
type _FILETIME
dwLowDateTime as dword
dwHighDateTime as dword
endtype
type _WIN32_FIND_DATA
dwFileAttributes as dword `0
ftCreationTime as _FILETIME `4 8
ftLastAccessTime as _FILETIME `12 16
ftLastWriteTime as _FILETIME `20 24
nFileSizeHigh as dword `28
nFileSizeLow as dword `32
dwReserved0 as dword `36
dwReserved1 as dword `40
cFileName as string `44+MAX_PATH-1 i.e. 260-1 = 259
cAlternateFileName as string `44+259+14
//dwFileType as dword // Obsolete. Do not use.
//dwCreatorType as dword // Obsolete. Do not use
//wFinderFlags as word // Obsolete. Do not use
endtype
#constant MAX_PATH 260
#constant SIZEOF_WIN32_FIND_DATA 320
#constant WINDOW_NORMAL 13565952
#constant INTERNET_OPEN_TYPE_PRECONFIG 0 // use registry configuration
#constant INTERNET_OPEN_TYPE_DIRECT 1 // direct to net
#constant INTERNET_OPEN_TYPE_PROXY 3 // via named proxy
#constant INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY 4 // prevent using java/script/INS
#constant INTERNET_DEFAULT_FTP_PORT 21
#constant INTERNET_SERVICE_FTP 1 // FTP service.
#constant INTERNET_SERVICE_GOPHER 2 // Gopher service.
#constant INTERNET_SERVICE_HTTP 3 // HTTP service.
#constant INTERNET_FLAG_PASSIVE 0x08000000 // FTP PASSIVE
`global pFindData as dword
global hNextFile as dword
global hFirstFile as dword
HttpAgent as string = "FTP Session"
NullString as string = ""
site as string = "<your site>"
sServerName as string = "<your server name>"
nServerPort as integer = INTERNET_DEFAULT_FTP_PORT
sUsername as string = "<your user id>"
sPassword as string = "<your password>"
`sServerName as string = "localhost" // for google drive ftp adapter
`nServerPort as integer = 1821 // for google drive ftp adapter
`sUsername as string = "user" // for google drive ftp adapter
`sPassword as string = "user" // for google drive ftp adapter
lService as integer = INTERNET_SERVICE_FTP
lFlags as integer = INTERNET_FLAG_PASSIVE
lContext as dword = 0
wininet = find free dll()
load dll "wininet.dll", wininet
if dll exist(1)=1
print "dll exists and loaded ok."
else
end
endif
kerneldll = find free dll()
load dll "kernel32.dll", kerneldll
if dll exist(1)=1
print "dll exists and loaded ok."
else
end
endif
hInternetSession as dword
hInternetSession = InternetOpen(wininet, HttpAgent, INTERNET_OPEN_TYPE_DIRECT, "", "" , 0)
print "hInternetSession: ";hInternetSession
if hInternetSession > 0
hConnection as dword
hConnection=SiteConnect(wininet, hInternetSession, sServerName, nServerPort, sUsername, sPassword, lService, lFlags, lContext)
print "hConnection: ";hConnection
checkconnected = SiteConnected(wininet,site,1,0)
print checkconnected
if checkconnected = 1
success=SiteSetDir(wininet,hConnection,"AutoWelder")
print "set folder success: ";success
curdir$=SiteGetDir(wininet, hConnection )
print curdir$
f$=SiteFirstFile(wininet, hConnection)
print f$, hFirstFile
repeat
f$=SiteNextFile(wininet, hConnection)
print hNextFile;" , ";f$
until hNextFile =0
r=call dll (wininet,"InternetCloseHandle", hFirstFile)
r=call dll (wininet,"InternetCloseHandle", hNextFile)
endif
endif
sync
wait key
if hConnection
r=call dll (wininet,"InternetCloseHandle", hConnection)
endif
If hInternetSession
r=call dll (wininet,"InternetCloseHandle", hInternetSession)
endif
delete dll wininet
delete dll kerneldll
`free pFindData
end
function InternetOpen(dllid, sAgent as string , lAccessType as integer , sProxyName as string , sProxyBypass as string , lFlags as integer )
h as dword
h=call dll(dllid,"InternetOpenA", sAgent, lAccessType, sProxyName, sProxyBypass , lFlags)
endfunction h
function SiteConnect(dllid, hInternetSession, sServerName as string , nServerPort as integer , sUsername as string , sPassword as string , lService as integer , lFlags as integer , lContext as dword )
h as dword
h=call dll(dllid,"InternetConnectA", hInternetSession, sServerName, nServerPort, sUsername, sPassword, lService, lFlags, lContext )
endfunction h
function SiteConnected(dllid, lpszUrl as string , dwFlags as integer , dwReserved as integer )
b as boolean
b = call dll (dllid,"InternetCheckConnectionA", lpszUrl, dwFlags, dwReserved)
endfunction b
function SiteSetDir(dllid, hConnect, folder as string )
b as boolean
b=call dll (dllid,"FtpSetCurrentDirectoryA",hConnect,folder)
endfunction b
function SiteGetDir(dllid, hConnect )
pCurrentDir as dword `pointer to Current Folder String
pBuffLen as dword `pointer to string buffer maximum length
lpszDirectory as string `buffer string containing the site current folder
pCurrentDir=alloc zeroed(MAX_PATH)
pbufflen=alloc(4)
poke dword pBuffLen,MAX_PATH
r = call dll(dllid,"FtpGetCurrentDirectoryA", hConnect, pCurrentDir, pBuffLen)
buflen=peek dword(pBuffLen)
lpszDirectory = peek string(pCurrentDir,buflen)
free pCurrentDir
free pBuffLen
endfunction lpszDirectory
function SiteFirstFile(dllid, hConnect)
`pFindData = alloc(SIZEOF_WIN32_FIND_DATA)
dim FindData(SIZEOF_WIN32_FIND_DATA)
pFindData = get arrayptr(FindData())
searchfile as string = ""
flags =0
context = 0
ff as string
global hFirstFile as dword
hFirstFile = call dll(dllid, "FtpFindFirstFileA", hConnect, searchfile, pFindData, flags, context)
if hFirstFile > 0 then ff=peek string(pFindData+44,MAX_PATH) ` +44 is the offset pointing to the filename
undim FindData()
endfunction ff
function SiteNextFile(dllid, hConnect)
` pFindData = alloc(SIZEOF_WIN32_FIND_DATA)
dim FindData(SIZEOF_WIN32_FIND_DATA)
pFindData = get arrayptr(FindData())
ff as string
hNextFile = call dll (dllid,"InternetFindNextFileA",hFirstFile,pFindData)
if hNextFile > 0 then ff=peek string(pFindData+44,MAX_PATH) ` +44 is the offset pointing to the filename
undim FindData()
endfunction ff
Professional Programmer, languages: SAS, C++, SQL, PL-SQL, DBPro, Purebasic, JavaScript, others