• Welcome, Guest. Please login.
August 15, 2020, 10:26:24 am


Welcome to the SQLitening support forums!

put get file

Started by D. Wilson, March 24, 2011, 07:34:10 pm

Previous topic - Next topic

D. Wilson

Is it possible to get a program example of uploading/downloading files using sqlitening ??

Fred Meier

This example works with a remote server.  The same code will work in
local mode without the slConnect.

   ' Connect to remote server

   ' Open the local file for binary.  It must already exist or an empty
   ' file will be created.
   open "LocalFileUploadExample.Txt" for binary as #1

   ' Get all the data from local file into variable lsA and close it
   get$ #1, lof(#1), lsA
   close #1

   ' Upload the data using C ModChar so file will be created if not already there.
   ' If file is already there then will overwrite.  For security reasons, all files
   ' must be included in the FACT of the server config file. This is because of the
   ' damage that can be done due to a coding error with PutFile.
   slPutFile "RemoteFileUploadDownloadExample.Txt", lsA, "C"

   ' Download the data from the server into variable lsA
   slGetFile "RemoteFileUploadDownloadExample.Txt", lsA

   ' Open the local file for binary.  An empty file will be created
   ' if it doesn't exist or it will overwrite.
   open "LocalFileDownloadExample.Txt" for binary as #1

   ' Put the date into local file from variable lsA and close
   put$ #1, lsA
   close #1

   ' Now LocalFileDownloadExample.Txt will be same as LocalFileUploadExample.Txt

D. Wilson

Thanks for the help. You saved me hours of head scratching.


'UpDown.bas   Works great!!
#COMPILE EXE "..\Bin\UpDown.exe"
#INCLUDE "..\Inc\SQLitening.Inc"
  LOCAL sServer, sFileName,sWrite,sRead, sResults AS STRING
  LOCAL PortNumber, counter, result AS LONG
  slSetProcessMods "E0"
  sServer = ""
  PortNumber = 51234
  result = slConnect(sServer, PortNumber)
  IF result THEN ? "Connect error"+ STR$(Result),%MB_ICONERROR,EXE.FULL$:EXIT FUNCTION
  FOR counter = 1 TO 10
    sFileName = "TEST1A.DAT"  'TEST1A.DAT in [FACT section]
    IF counter = 4 THEN sFileName = "" 'create an error
    sWrite = SPACE$(counter * 100000)
    result = slPutFile(sFileName, sWrite,"C")
    IF result THEN  sResults = sResults + "Put error" + STR$(result)+ $CR
    result = slGetFile(sFileName, sRead)
    IF result THEN  sResults = sResults + "Get error" + STR$(result) + $CR
    sResults = sResults + FORMAT$(LEN(sRead),"#,") + " bytes" + $CR
  ? sResults,,EXE.FULL$