Access to and from a server on the global internet.

Remote server storage on the internet.

You can get space on a remote server for free, or by paying. You could also set it up on a computer of your own that you are prepared to run 24/7 and if you are prepared to do some installation/customisation. By using a remote commercial server you don't have to pay for 24 hours of electricity per day, but more importantly they can guarantee 99.9% availability, backups, and other conveniences. Particularly, you don't have to know how to 'harden' your personal machine against possible intrusion when you open ports to the world nor need to have a permanent web address- the commercial server ensures that.

Free services like DriverHQ may limit number of accesses per day: others like Meirhosting charge under 3ukp per month with 100MB of storage.

If you have space on such a server, you can use it, integrated to your local file management, as a file store/backup, much like a 'cloud service', with a GUI interface, like DropBox etc. But importantly you can also access it via ftp- file transfer protocol- from Liberty BASIC.

Caution. ftp files are transferred with no encryption and potentially could be intercepted in a 'man in the middle' attack. SECURE ftps or sftp are also possible but I haven't tried them from LB. My 'own' digame server is commercial and I do not divulge the username and password and I use secure ftp /https) on it. I set up a free ftp server on DriverHQ and that is what I access with LB. I can risk letting others know such a username/password only if I trust them. They can then add new files- or delete mine. I keep backups of files on this 'sacrificial' server just in case.

Web pages ( http/https) are served by you up to your server, and out to the world wide web by a server, too. You upload them to the server by ftp/ftps/sftp. Your passworded access allows you to upload new pages, or edit/delete existing pages.

So how do I use Liberty BASIC for this server access?

You can use the command httpget$ to bring an internet file to your machine and do things with it. If it's an http file you can display it in a browser. For other file types you could play audio MP3, or show and alter an image, analyse a file, etc.

By using a dll called ftp4w32.dll you can move files up to or down from the server.

As an example, LB code can run on one machine and upload your choice of file. Anyone else on the 'web can view/download the file. Only someone who knows your username and password can alter the file or upload their own files. If you distribute as an exe( tkn) file you can encrypt these details such that the program can decode and use them, but a casual user would have no idea of what was going on... and be unable to choose files and send/receive other than what your code specified.

One of my examples takes a snapshot at 1 minute intervals of part of my home screen, and sends them to my ftp server. Its twin program, run in LB anywhere on the internet can access and process the file. And any web viewer can display it. For security I obviously don't have anything I wish to keep secret on that section of screen- I set it just to show my icon bar display of the time/date. For the screenshot below I temporarily increased the height of the grabbed/displayed section. You should be able to see why it could be a big security problem!!

Below is the view from a web browser ( anywhere in the world) of the bottom right of my screen. I ran it for a few days when testing. Note I'd set it up so sensitive information would not be on screen at that time!

Another example would be a game you distribute in tkn form, that is a game for users. LB could send the user's 'handle' and latest score to the server. You, on your own machine, could run code that gathers any new results each day, orders them, and puts them back on the server. When any player any computer next runs their copy, it would load the file and display it, much encouraging competivity!

One of my first LB programs, back on v1.4, operated in a similar way on my school network, where as staff/admin I could access the student's own results in their school network space. Reactions. No privacy significance- They knew we had access to their files, and I used the data anonymously. It classified reaction times and saved them along with which hand was used, choice of keys to use, age and sex. This allowed me to draw conclusions with some validity by doing statistics on the correlations, and on consistency ( accurately repeatable results) or wild ones ( sometimes very fast but making mistakes too often). Are girls faster/slower? Are boys fast but wilder? Are left-handers same speed as right-handers? I gathered several hundred results from each year's new students.

It's still on my website...


Example LB Code- send grabbed image of part of screen to web server

NB You will need a working server- ftp only, or full web server

You also need the dll.



'                                     ftpScreenToServer4c.bas

'   ************************************************** ***********************************************
'   *                                                                                                *
'   *                             ftp screenGrab & html to remote server                             *
'   *                                                                                                *
'   ************************************************** ***********************************************


    xS =650: yS =610: wS =714: hS =157

    timer 60000, [snapshot]                         'every 60 seconds

    global ftp, parentftp, port, pasv, ftphost$, login$, password$, initPath$, upload$
    global backLocal$, newDir$, TRUE, FALSE, ftpsession, serverFile$, xS, yS, wS, hS

    port          = 21                              'port to use.
    pasv          =  1                              'PASV mode? 1 is yes, 0 is no.

    ftphost$      = "ftp.drivehq.com"          'ftp site address.
    login$        = "**************"           'ftp site username login.
    password$     = "*****************"        'ftp site password.

    initPath$     = ""                              'leave blank if you want the site's default. Otherwise name of work dir'y on server.
    upload$       = ""                              'full path & file info for local file to upload.
    serverFile$   = ""                              'what file is called on the ftp server.
    backLocal$    = ""                              'what to call the returned local downloaded file.

    TRUE          = 1
    FALSE         = 0

    ftpsession    = FALSE

    nomainwin                                       '   REM out when testing

    WindowWidth =200:  WindowHeight =100

    open "Test ftp routines" for window as #w         '  routines need a window handle. Can be tiny or even off-screen...

    #w "trapclose quit"

    wait
'   **************************************************************************************

    sub action command$     '   Implements at present file upload /download ( and remote direstory up /down /listing.)
        open "ftp4w32.dll" for dll as #ftp
        ftpsession  = TRUE

        calldll #ftp, "FtpInit",               parentftp as long,                                                                               res  as long
        calldll #ftp, "FtpSetSynchronousMode",                                                                                                  void as long
        calldll #ftp, "FtpSetDefaultPort",     port as long,                                                                                    void as long
        calldll #ftp, "FtpSetPassiveMode",     pasv as long,                                                                                    void as long
        calldll #ftp, "FtpLogin",              ftphost$ as struct,  login$ as struct,     password$ as struct,    parentftp as long, 0 as long, res  as long

        if instr( upload$, "/") then upload$     =afterlast$( upload$, "/")

        if command$ ="Upload" then
            type$   ="I"    '   A =ASCII, I =Image ie binary
            type    =asc( "I")
            calldll #ftp, "FtpSetType",  type       as long,   res as long
            calldll #ftp, "FtpSendFile", upload$    as struct, serverFile$ as struct, 0 as long, 0 as long, parentftp as long, 0 as long, res as long
        end if

        call Pause 200

        calldll #ftp, "FtpCloseConnection", void as long
        calldll #ftp, "FtpRelease",         void as long
        close   #ftp

        ftpsession = FALSE
    end sub

    sub quit h$
        close #w
        if ftpsession = TRUE then
            calldll #ftp, "FtpCloseConnection", void as long
            calldll #ftp, "FtpRelease",         void as long
            close   #ftp
        end if
        end
    end sub


    function error$( n)
        select case
            case n =0
                error$ ="No problem"
            case n =1003
                error$ ="User not connected to server"
            case n =1004
                error$ ="Cannot open file"
            case n =1008
                error$ ="Action not taken"
            case n =1010
                error$ ="Server cannot open file"
            case else
                error$ ="Other unrecognised error "; n
        end select
    end function

    sub Pause mil
        t    =time$( "milliseconds")
        while time$( "milliseconds") <( t +mil)
            '
        wend
    end sub

[snapshot]
    timer 0
    loadbmp "snap", screenShot( xS, yS, wS, hS)     '   saves desired screen area as bmp
    upload$         ="snapshot.bmp" ' +right$( "00000000" +str$( time$( "seconds")), 8) +".bmp"                '   local filename for upload
    bmpsave "snap", upload$
    serverFile$     =upload$                        '   name to save it as on server
    call action "Upload"
    timer 60000, [snapshot]
    wait


function screenShot( x, y, w, h)
    n$      =chr$( 0)
    CallDLL #gdi32, "CreateDCA",                "DISPLAY" As ptr,   n$      As ptr,  n$ As ptr,  n$ As ptr,  scrDC As ulong
    CallDLL #gdi32, "CreateCompatibleDC",       scrDC As ulong,     comDC   As ulong

    CallDLL #gdi32, "CreateCompatibleBitmap",   scrDC As ulong,     w    As long,    h          As long,   bmp As ulong
    CallDLL #gdi32, "SelectObject",             comDC As ulong,     bmp  As ulong,   mbmp       As ulong
    CallDLL #gdi32, "BitBlt",                   comDC As ulong,     0    As long,    0          As long,   w As long,          h As long,_
                                                scrDC As ulong,     x    As long,    y          As long,   _SRCCOPY As long,   ret As long
    CallDLL #gdi32, "SelectObject",             comDC As ulong,     mbmp As ulong,   screenShot As ulong
    CallDLL #gdi32, "DeleteObject",             mbmp  As ulong,     ret  As long
    CallDLL #gdi32, "DeleteDC",                 scrDC As ulong,     ret  As long
    CallDLL #gdi32, "DeleteDC",                 comDC As ulong,     ret  As long
end function