hey, i'm wondering if it is possible to get the contents of a file that is stored on a web sever using EBASIC? i am trying to make a program that lets you know if a web page has changed since the last time you checked so far the idea is to use php on the web server to opened the file and get a hash code then write the hash to a text file which is then ether downloaded and opened with EBASIC or opened right on the sever. my question is how to i get EBASIC to fetch a file that's not on the local computer?
If I was going to try it I would create a window then attach a browser to it then load the web page into that.
Look at the section in the help file labeled "Creating Embedded Browsers"
Some of the other members might know a "slicker" way.
Larry
thanks for the info but that not quite what i want. what i want to end up with is the hash code in a string so i can work with it, unless i'm missing something i don't see how that can be done by attaching a browser window anyother ideas?
chris
I guess I was thinking of "posting" form data from a web page which EB can do.
There's a lot of server stuff that people do.
Maybe Sapero can help you.
Sorry,
Larry
thanks for trying and i am glad i found that so i don't need to work out how to close IE from EBASIC now
Not sure what you mean but when you attach a brower window to EB you use the ATTACHBROWSER command and when you get through with it you just close the window you attached it to (which could be a child window of another window like I use it)
Larry
just thought of another way.
You can use the SYSTEM command in EB to run external programs (and if you use the API ShellExecuteExA you can run them hidden).
Then if you had an ftp program that would accept command line arguments then you could download the file that way.
Just brainstorming,
Larry
well i'm going to tell the php script what to get the hash code of by useing GET because its shown in the url which means i can easly change what i send. i was thinking i would have to use the SYSTEM comand to open Internet Explorer and go to the webpage the problem was how do i then close Internet Explorer once i was done with it
and thanks for the FTP idea but i'd need to find ne i can give away that dosn't need any work to get up and running as i'm giveing out the program once it is ready if it was just for me i wouldn't bother with the EBASIC and just use the PHP it just takes awhile to set up and forward your own sever
Here is some code that I use a lot.
$main
$use "version.lib"
$use "wininet.lib"
'API imports needed
DECLARE IMPORT,VerQueryValueA(pBlock as POINTER ,lpSubBlock as POINTER,lplpBuffer as POINTER,puLen as POINTER),INT
DECLARE IMPORT,GetFileVersionInfoSizeA(lptstrFilename as STRING,lpdwHandle as POINTER),UINT
DECLARE IMPORT,GetFileVersionInfoA(lptstrFilename as STRING,dwHandle as UINT,dwLen as UINT,lpData as POINTER),INT
DECLARE IMPORT,InternetOpenA(agent as string,access as int,proxyname as string,proxybypass as string,flags as int),int
DECLARE IMPORT,InternetConnectA(session as int,server as string,port as word,username as string,pass as string,service as int,flags as int,context as int),int
DECLARE IMPORT,InternetCloseHandle(handle as int),int
DECLARE IMPORT,HttpOpenRequestA(session as int,verb as string,name as string,version as pointer,referer as string,types as pointer,flags as int,context as int),int
DECLARE IMPORT,HttpSendRequestA(handle as int,headers as pointer,headerlength as int,option as pointer,optionlength as int),int
DECLARE IMPORT,InternetReadFile(hfile as int,buffer as pointer,count as int,bytesread as pointer),int
DECLARE IMPORT,InternetQueryDataAvailable(hfile as int,bytesavail as pointer,flags as int,context as int),int
DECLARE IMPORT,HttpQueryInfoA(hReq as UINT,dwInfo as UINT,lpvbuffer as pointer,lpdwlength as pointer,lpdwindex as pointer),INT
DECLARE IMPORT,InternetGetConnectedState(state as UINT BYREF,reserved as UINT),int
'TYPE needed
TYPE VS_FIXEDFILEINFO
UINT dwSignature
UINT dwStrucVersion
UINT dwFileVersionMS
UINT dwFileVersionLS
UINT dwProductVersionMS
UINT dwProductVersionLS
UINT dwFileFlagsMask
UINT dwFileFlags
UINT dwFileOS
UINT dwFileType
UINT dwFileSubtype
UINT dwFileDateMS
UINT dwFileDateLS
ENDTYPE
'constants
SETID "INTERNET_SERVICE_FTP",1
SETID "INTERNET_SERVICE_GOPHER",2
SETID "INTERNET_SERVICE_HTTP",3
SETID "INTERNET_PRECONFIG",0
SETID "INTERNET_DIRECT",1
SETID "INTERNET_PROXY",3
SETID "INTERNET_FLAG_RELOAD",0x80000000
SETID "INTERNET_FLAG_NO_CACHE_WRITE",0x04000000
SETID "HTTP_QUERY_CONTENT_LENGTH",5
SETID "HTTP_QUERY_STATUS_CODE",19
SETID "HTTP_QUERY_FLAG_NUMBER",0x20000000
'template for our progress callback
declare progresscb(uint totalsize,uint current)
'gets a file from the server and saves it to disk.
SUB DownloadToFile(server as string,remote as string,local as string,progCallback as UINT),int
STRING referrer:referrer = "EBasic Client"
char buffer[1024]
UINT hOpen,hconnect,hhttp,dwSize,dwSizeLen,dwCurrent,statuscode
BFILE fSave
int br:br = 0
int success:success = FALSE
string _temp:_temp=getstartpath+"__"+local
hopen = InternetOpenA(referrer,@INTERNET_PRECONFIG,"","",0)
if(hopen)
hconnect = InternetConnectA(hopen,server,80,"","",@INTERNET_SERVICE_HTTP,0,0)
if(hconnect)
hhttp = HttpOpenRequestA(hconnect,"GET",remote,null,"",null,@INTERNET_FLAG_RELOAD|@INTERNET_FLAG_NO_CACHE_WRITE,0)
if(hhttp)
IF HttpSendRequestA(hhttp,null,0,null,0)
'get the size of the remote file, if available
dwSizeLen = 4
dwSize = 0
dwCurrent = 0
HttpQueryInfoA(hhttp,@HTTP_QUERY_CONTENT_LENGTH|@HTTP_QUERY_FLAG_NUMBER,dwSize,dwSizeLen,NULL)
HttpQueryInfoA(hhttp,@HTTP_QUERY_STATUS_CODE|@HTTP_QUERY_FLAG_NUMBER,statuscode,dwSizeLen,NULL)
'download and store the file
' only attempt to download the file if it really exists and is available
' otherwise the buffer contains an html document with "404 not found, 403 server error, etc".
if statuscode = 200
if(OpenFile(fSave,_temp,"W") = 0)
DO
InternetReadFile(hhttp,buffer,1024,br)
if br
dwCurrent += br
__write(fSave,buffer,br)
if(progCallback)
!<progresscb>progCallback(dwSize,dwCurrent)
endif
endif
UNTIL br = 0 or CancelDownload=true
CloseFile(fSave)
if CancelDownload=FALSE
CopyFile(_temp, getstartpath+local, 0)
endif
DeleteFile(_temp)
if CancelDownload=TRUE then success=FALSE else success = TRUE
endif
endif
else
MessageBox update,"Cannot connect to server\nPlease check your internet connection and try again","Error",@MB_ICONEXCLAMATION
bStart = FALSE
CloseWindow update
ENDIF
InternetCloseHandle(hhttp)
endif
InternetCloseHandle(hconnect)
endif
InternetCloseHandle(hopen)
endif
RETURN success
ENDSUB
wow... just wow that’s going to take awhile to work out but thanks showing me it can work here i was hoping for something simple :) but i'll take what i can get thanks chris
okay i tryed to compile the code as you gave it but i got a wack of errors
Compiling...
downlodeFile.eba
File: C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba (88) undefined variable - CancelDownload
File: C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba (90) undefined variable - CancelDownload
File: C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba (94) undefined variable - CancelDownload
File: C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba (98) undefined variable - update
File: C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba (98) invalid parameter
File: C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba (100) undefined variable - update
File: C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba (100) no appropriate conversion exists
Error(s) in compiling "C:\Program Files\EBDev\projects\Database samples\downlodeFile.eba"
any ideas on what i have to do to fix it? and while i'm at it how do i tell it what file to get and what sever to get it from?
Well there are easier ways,this one just has the most flexibility since you can check the status code of the remote file, 304 means not modified.
Currently it is set up to always get the remote file, and ignore any locally cached copies. Which is necessary if you are retrieving a file that changes frequently.
You may need to do some research on the functions, use google ;).
Paul.
It's not meant to compile directly, just ripped out of one of my programs. CancelDownload is just defined as an INT and my progress dialog has a "Cancel" button that sets it to 1. Just define it as an INT somewhere in your program, and set it to 0.
"update" was the window variable in my program. Just comment the line out.
server = "http://www.yourwebsite.com"
remote = "downloads/myfile.whatever"
I can't tell you the server and remote, you are the one that knows that ;)
thansk it compiles now but i'm still not getting a file saved where i want it is local there varable that tells the program where to save the file?
the local parameter of the function is where you specify where the file gets saved: ie
DownloadToFile("http://www.test.com","file.txt","c:\\myfiles\\file.ext",NULL)
okay so i added this to the end of the code and its still not working i'm sure that i've got the right information so what am i doing wrong?
IF DownloadToFile("http://www.authorskeep.com/","/home/authorsk/public_html/fallen/index.php","C:\\Users\\chris\\Downloads\\index.php",NULL)
PRINT "It worked"
ENDIF
DO : UNTIL INKEY$<>""
chris,
try:
DownloadToFile("http://www.authorskeep.com","index.php","C:\\Users\\chris\\Downloads\\index.php",NULL)
The full server path isn't remotely accessable, only whatever is off of public_html, hence the name.
Why are you trying to download the index.php file?
Paul.
okay i tryed useing
DownloadToFile("http://www.authorskeep.com","index.php","C:\\Users\\chris\\Downloads\\index.php",NULL)
but no luck is there anything on the server side that needs to set?
P.S i'm trying to get index.php to see if it works no other reson
Forgot....don't use the http:
DownloadToFile("www.authorskeep.com","index.php","C:\\Users\\chris\\Downloads\\index.php",NULL)
It's just the servers address, or IP address.
if .php files don't work then try a simple text file to experiment with.
allright its still not working anything else to try? or is there anyother way to get data off of a sever?
I use that subroutine in a production environment to update frequently changed client files, multi megabytes worth, never fails. Have never tried it with a .php file which is why I suggested to try a .txt file to experiment with. Most likely server security settings are preventing a direct GET of files with a .php extension.
Insert some print statements to see where it is failing for you. Do some debugging, it is what programming is all about.
Quote
is there anyother way to get data off of a sever?
Probably dozens, this is the easiest way I know of which allows bypassing the IE cache so you can get to a file that might have changed since the last time you read it. You could use winsock direclty, but that would require pages of code.
See the test program internet_example.eba that comes with the installation for a slightly scaled down version of the provided subroutine.
Paul.
thanks for the help i'm just glad that it can be done i'll kep working on it then
yours chris
Chris
Did you ever get it working for you?
If you didn't I can help.
Larry
Paul,
Is there a way to make your routine work with a "generated" page?
The call to the sub would look like this:
DownloadToFile("www.blah.com","isapi.dll?c=c",getstarpath+"tmp.txt",NULL)
Larry
No idea, have you tried it?
The routine was designed specifically to download files for a site, executables, zips, images, etc.
Paul.
Yeah, I tried it. It connects and then the program just sits there like it is waiting on something.
Not something I HAVE to have.
Larry
If you give me the page you are trying to reach than I'll play when I get time.
Paul.
Naaaaa
You've got better things to be doing.
And like i said, it's not something of great importance to me.
Larry
Ok, if you change yer mind then give a yell.
Paul.
You bet, thanks.
I'll save my "holler for help" for something that isn't just an after thought.
Larry
okay after a lot of testing i found the bit that is messing up i just don't know what it dose
IF HttpSendRequestA(hhttp,null,0,null,0)
so what dose that do? and how can i fix it?
thanks in advance
chris
That sends your request to the server. So the server responded you didn't send a valid request.
Which means either the server doesn't exits, the path to the document is wrong, or the sever doesn't support a GET of that file type.
Google it (http://www.google.com/search?hl=en&q=HttpSendRequest&btnG=Google+Search)
It is a Windows function, the very first link is the Microsoft documentation for it.
Paul.
okay i'll do that thanks for the help