turtle1776's FTP stuff

BlitzMax Forums/BlitzMax Programming/turtle1776's FTP stuff

Rimmsy(Posted 2005) [#1]
Hello again. I'm trying to port turtle's ftp stuff from the archive ( http://www.blitzbasic.com/codearcs/codearcs.php?code=1444 ) which is pretty spanking. In fact it even allows me to upload to my webspace when other ftp programs don't. I'm not sure how but that program is my only way of uploading. Therefore I'd like to attempt to port it to bmx so I can write some useful utils with it. I'm stuck though. I'm not adept at porting (my first time) and I was wondering whether any of you kind souls could help me out with a few things.

Turtle has the following decls entries. I can add them to a decls with blitz3d and the ftp program runs fine. I'm not sure how they translate across to bmx.

;Add to decls file
;------------------
;.lib "wininet.dll"
;FtpCreateDirectory%(hFTPSession%,lpszDirectory$):"FtpCreateDirectoryA"
;FtpDeleteFile%(hFTPSession%,lpszFileName$) : "FtpDeleteFileA"
;FtpFindFirstFile%(hFTPSession%,lpszFileName$,lpFindFileData*,dwFlags%,dwContext%) : "FtpFindFirstFileA"
;FtpGetCurrentDirectory%(hFTPSession%,lpszCurrentDirectory*,neededLength*):"FtpGetCurrentDirectoryA"
;FtpGetFile%(hFTPSession%,RemoteFile$,LocalFile$,fFailIfExists%,dwFlagsAndAttributes%,dwFlags%,dwContext%):"FtpGetFileA"
;FtpPutFile%(hFTPSession%,LocalFile$,NewRemoteFile$,dwFlags%,dwContext%):"FtpPutFileA"
;FtpRemoveDirectory%(hFTPSession%,lpszDirectory$) : "FtpRemoveDirectoryA"
;FtpRenameFile%(hFTPSession%,lpszExisting$,lpszNew$) : "FtpRenameFileA"
;FtpSetCurrentDirectory%(hFTPSession%,lpszDirectory$) : "FtpSetCurrentDirectoryA"
;InternetCloseHandle%(hInternet%):"InternetCloseHandle"
;InternetConnect%(hInternet%, ServerName$, ServerPort%, Username$, Password$, Service%, Flags%,  dwContext%):"InternetConnectA"
;InternetFindNextFile%(hInternet%,lpvFindData*) : "InternetFindNextFileA"
;InternetOpen%(Agent$, AccessType%, ProxyName%, ProxyBypass%, Flags%):"InternetOpenA"
;InternetGetLastResponseInfo%(lpdwError*,lpszBuffer*,lpdwBufferLength*) : "InternetGetLastResponseInfoA"


Something like this:
Global wininetLib = LoadLibraryA("wininet.dll")
Global FtpCreateDirectory(hFTPSession:Int, lpszDirectory$)"win32"=GetProcAddress(wininetLib,"FtpCreateDirectoryA")

What does :Byte Ptr mean in this situtation? And also, in the bb code what does the * mean?
InternetGetLastResponseInfo%(lpdwError*,lpszBuffer*,lpdwBufferLength*) : "InternetGetLastResponseInfoA"


I'd love to use them. Any help is greatly appreciated. Also, thanks to turtle for this code in the first place. You da man.


Rimmsy(Posted 2005) [#2]
Ok, I've sorted the String bits by adding a :Byte Ptr instead, so it reads:
Global InternetConnect(hInternet:Int, ServerName:Byte Ptr, ServerPort:Int, Username:Byte Ptr, Password:Byte Ptr, Service:Int, Flags:Int, dwContext:Int)"win32"=GetProcAddress(wininetLib,"InternetConnectA")
And I use a toCString()

I'm now stuch at the getFileList function. Turtle's using banks and I'm not quite sure what's happening although I'm pretty sure bmx doesn't need this. Anyone got an alternate, easy version of the function below:
Function ReadAPIString$(bank,offset=0)
	size = BankSize(bank)
	For x = offset To (size-1)
		If PeekByte(bank,x) = 0 Then Exit 'Null terminator found
		myString$ = myString$ + Chr$(PeekByte(bank,x))
	Next	
	Return myString$
End Function

What does it do? And why?


Rimmsy(Posted 2005) [#3]
;FtpGetCurrentDirectory%(hFTPSession%,lpszCurrentDirectory*,neededLength*):"FtpGetCurrentDirectoryA"
=
Global FtpGetCurrentDirectory(hFTPSession:Int, lpszCurrentDirectory ?? ,neededLength ?? )"win32"=GetProcAddress(wininetLib,"FtpGetCurrentDirectoryA")

I see that turtle's passing a bank through the FtpGetCurrentDirectory function (by reference?) and the function is filling the bank with data. Then, when the function has been run, the bank should be full of information that the FTPGetFileList function uses to retreive the file name, size, etc.

Inside the FTPGetFileList function:
	Repeat				
		f:ftpfile = New ftpfile	
		f.directory$ = remoteDirectory$
		f.fileName$ = ReadAPIString$(lpFindFileData,44)
		If PeekInt(lpFindFileData,0) = 16 Then f.typeOfFile = 2 'directory (FILE_ATTRIBUTE_DIRECTORY)
		If PeekInt(lpFindFileData,0) = 128 Then f.typeOfFile = 1 'file (FILE_ATTRIBUTE_NORMAL)
		f.sizeofFile = PeekInt(lpFindFileData,32)	 'nFileSizeLow is enough, accurate For files < 2.1 gigs (that's huge)			
	Until InternetFindNextFile(hInternet,lpFindFileData) = 0

So, according to the above, the filename is retreivable from an offset of 44. I'm not sure what's going on. Any help?


Rimmsy(Posted 2005) [#4]
Ok, never mind, I'll leave it. I'll just use the bb code as-is.