|
Post by atomose on May 6, 2022 15:25:10 GMT -5
Hi,
I need help to know if it is possible to:
when I read a file on my server with an address "http\\ip_adress\file.txt" I can read the file and take a variable from it then use it on the LB program with the "input" command BUT how can I then send new information (a modification of this variable for example) to the address of this file? I can do it one way but not the other.
(I don't know if you understand me ^^)
|
|
|
Post by Brandon Parker on May 6, 2022 21:43:16 GMT -5
That really depends on what is happening on the other end. If the server you are communicating with has some REST functionality set up then you may be able to send data very easily, but otherwise, it might be more difficult. We would need to know what you are communicating with on the other end to provide more detailed help.
{:0)
Brandon Parker
|
|
|
Post by Chris Iverson on May 6, 2022 23:44:55 GMT -5
What Brandon said. The server has to be set up to allow it, and you have to transmit the data in a specific way. You can't just tell a server "here's the new file" and be done with it. EDIT: Here's a very rudimentary example of the server changing data in response to what the client says: print httpget$("https://chrisiverson.net/ClientDataTest.php")
print httpget$("https://chrisiverson.net/ClientDataTest.php?data=blahblahblah")
If you just browse to chrisiverson.net/ClientDataTest.php, you'll just get "Default" back as the text. If you add anything to the data parameter in the URL(like chrisiverson.net/ClientDataTest.php?data=blahblahblah ), that data will get echoed back. However, this requires the server code to be explicitly looking for that. if ( $_GET["data"] ) { echo $_GET["data"]; } else { echo "Default"; } EDIT2: LOL PHP code gets blocked if you include the opening and closing PHP flags. Good to know, and probably not a bad idea.
|
|
|
Post by tenochtitlanuk on May 7, 2022 3:12:40 GMT -5
Not sure quite what your program/server set up is. But if you have a server and password to control it, you can httpget to receive data from it and ftp to return a file- whether the modified original or a completely new one. No need for over-complication. Only problem would be if you were trying both directions simultaneously. See an early example on my LB pages at Using server files over 'net
|
|
|
Post by atomose on May 7, 2022 4:27:26 GMT -5
hi, thx for help. I use www.rejetto.com/hfs/?f=dl as host serveur and i just put maj.txt into the "virtual file system" part. I really dont know how server work so i make it as simple as it possible ^^. it for fine for read the file (right click, take url, read the url) but i dont have option for able something ^^. EDIT : tenochtitlanuk, when i use your code i have this line (i removed nomainwin) : "1003 user not connected to server" or "protection violation" and crash
|
|
|
Post by Chris Iverson on May 7, 2022 12:33:00 GMT -5
Interesting tool.
First of all, they call out in their documentation that if you want to upload files, you need to use a Real folder, not a Virtual one.
Uploading would require a different set of API calls, I'll try to see if I can throw a demo together.
|
|
|
Post by tenochtitlanuk on May 7, 2022 16:12:30 GMT -5
Also...
Will HFS support the FTP file transfer protocol? FTP support is planned, but don't expect it soon. It may come in a major release after 2.0.
I'm used only to hosting on a ( paid) remote site or on my own SAMBA server, so can't help on HFS, tho' it seems an interesting system. I'm not keen on systems that require my own server to be on 24/7, plus the need to be more careful about firewalling etc, so I pay for someone else to ensure 99.9% availability
|
|
|
Post by Chris Iverson on May 7, 2022 23:43:20 GMT -5
Alright, using HFS, if you have a "real" folder setup with the name "html", and you can upload to it without needing a username/password, you can use this code below to perform the upload.
file$ = StartupDir$ + "freeform.CNT"
'Ending slash is important! serverPath$ = "http://localhost/html/" uploadFileName$ = "freeform.CNT"
print "====LOOKING FOR FILE ON SERVER====" print httpget$(serverPath$ + uploadFileName$) print print "====UPLOADING FILE===="
open file$ for input as #file fileData$ = input$(#file, lof(#file)) close #file
print doFileUpload$(serverPath$, uploadFileName$, fileData$) print print "====GETTING FILE FROM SERVER AGAIN====" print httpget$(serverPath$ + uploadFileName$)
print "Done."
'================================================= Function doFileUpload$(serverPath$, fileName$, fileData$) serverPort = 80 if left$(serverPath$, 7) = "http://" then serverPath$ = right$(serverPath$, len(serverPath$) - 7) end if
if left$(serverPath$, 8) = "https://" then serverPath$ = right$(serverPath$, len(serverPath$) - 8) serverPort = 443 end if
serverName$ = left$(serverPath$, instr(serverPath$, "/") - 1) uploadPath$ = right$(serverPath$, len(serverPath$) - instr(serverPath$, "/"))
open "WININET.DLL" for dll as #net calldll #net, "InternetOpenA", "LB HFS Upload Test" as ptr, 0 as long, _ 0 as long, 0 as long, 0 as long, hnet as ulong
calldll #net, "InternetConnectA", hnet as ulong, serverName$ as ptr, _ 'A free online resource to check API calls serverPort as long, 0 as long, 0 as long, 3 as long, 0 as long, 1 as long, hcnt as ulong
INTERNET.FLAG.SECURE = hexdec("800000") if serverPort = 443 then httpFlag = INTERNET.FLAG.SECURE else httpFlag = 0 end if calldll #net, "HttpOpenRequestA", hcnt as ulong, "POST" as ptr, uploadPath$ as ptr, _ 0 as long, 0 as long, 0 as long, httpFlag as long, 1 as long, hrqst as ulong
mimeBoundary$ = "----LB-HFS-Upload-Test-Boundary-" rndChrs$ = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
for x = 1 to 16 mimeBoundary$ = mimeBoundary$ + mid$(rndChrs$, int(rnd(1) * len(rndChrs$)), 1) next x
crlf$ = chr$(13) + chr$(10) qt$ = chr$(34) header$ = "Content-Type: multipart/form-data; boundary=" + mimeBoundary$ headerlen = len(header$)
content$ = "--" + mimeBoundary$ + crlf$ content$ = content$ + "Content-Disposition: form-data; name=" + qt$ + "file" + qt$ + "; filename=" + qt$ + fileName$ + qt$ + crlf$ content$ = content$ + "Content-Type: application/octet-stream" + crlf$ content$ = content$ + crlf$ content$ = content$ + fileData$ + crlf$ content$ = content$ + "--" + mimeBoundary$ + "--" + crlf$ contentLen = len(content$)
calldll #net, "HttpSendRequestA", hrqst as ulong, header$ as ptr, headerlen as long, _ content$ as ptr, contentLen as long, res as ulong
''''''''''''''''''''''''''''''''''''''' 'Now read the echo from the php script! '''''''''''''''''''''''''''''''''''''''
'Variable for message buffer$ = space$(500)
'Pointer for the initial buffer size and then how much was actually written struct bufferLength, bLength as long bufferLength.bLength.struct = len(buffer$)
'Pointer for header indexes, once returned, this is the next header struct index, bindex as long index.bindex.struct = 0
'HTTP_QUERY_STATUS_TEXT is defined as 20 in wininet.h HTTP.QUERY.STATUS.CODE = 19
calldll #net, "HttpQueryInfoA", hrqst as ulong, _ 20 as long, buffer$ as ptr, bufferLength as struct, index as struct, res as long
HTTP.QUERY.CONTENT.LENGTH = 5
buffer$ = space$(500) bufferLength.bLength.struct = 500
calldll #net, "HttpQueryInfoA", hrqst as ulong, _ 5 as long, buffer$ as ptr, bufferLength as struct,_ index as struct, res as long
bufLen = val(buffer$) buf$ = space$(bufLen) struct a, bytesRead as ulong
callDLL #net, "InternetReadFile", hrqst as ulong,_ buf$ as ptr, bufLen as long, a as struct,_ ret as long
doFileUpload$ = left$(buf$, a.bytesRead.struct)
'Alt attempt 'calldll #net, "InternetGetLastResponseInfoA", bufferLength as struct, buffer$ as ptr, index as struct, res as long 'print "Reply: ";res;" ";buffer$
calldll #net, "InternetCloseHandle", hrqst as ulong, res as long calldll #net, "InternetCloseHandle", hcnt as ulong, res as long calldll #net, "InternetCloseHandle", hnet as ulong, res as long close #net End Function
Edit: Fixed a bug in the code.
|
|
|
Post by atomose on May 8, 2022 13:06:22 GMT -5
hi !
thx for this quick post. I test the code and i have 2 errors (not with LB code but with HFS tools).
- Fist is "Not allowed" .... XD how can i allow it ? i dont see the option ^^
- second is "error creating file" (i changed some setting so its maybe my fault ....)
i change freeform.CNT to maj.txt, is it important ? thx (and nice job !)
work perfectly !!!! your the best XD !!! thxxxxx !!!!!
|
|