Post by Roger Cabo on Apr 30, 2022 18:56:42 GMT 1
Hi everyone,
------------------------------------------------------------------------------
these days online connection is very important. The most exe files are able to connect to a server. Then send/read any files, create/remove/rename folders, ask files or folders if they exist on a server. But GFA Basic does not have any internal functions for files transferring etc.
In the past (about 10 years ago) created a a complete code set to handle all this stuff by FTP.dll transfer. Unfortunately the FTP protocol is completely open and readable by the program "wire shark".
The SFTP protocol is secure, because you must install a certification on the web server. Then you can access the server per program code. One of the quality sftp.dl is chillkat. www.chilkatsoft.com/
In the past (about 10 years ago) created a a complete code set to handle all this stuff by FTP.dll transfer. Unfortunately the FTP protocol is completely open and readable by the program "wire shark".
The SFTP protocol is secure, because you must install a certification on the web server. Then you can access the server per program code. One of the quality sftp.dl is chillkat. www.chilkatsoft.com/
But I never got it to work.. My FTP solution works perfect in asynchronous mode. Means, you can send and receive files (etc...) without blocking GFA Basic.
It took me over a half year to develop this complex ftp communication in GFA basic.
My question: does anyone have another solution in GFA to send/receive/create/rename files and folders to a standard web server via sftp or http?
------------------------------------------------------------------------------
Here is an example how complicated is to receive a file. And there are so many pitfalls, you would not believe, For example::what happen if the file does not exist, or is corrupt, or have wrong content, or hangs, on the server. Or the server is suddenly not reachable while downloading, because someone unplugged the LAN cable. Further you have to take case of package slices as well and trace all actions. Otherwise you can't find errors.
Another cheesy thing is that all strings are readable in GFA Basic. So if you connect to a server by :
Another cheesy thing is that all strings are readable in GFA Basic. So if you connect to a server by :
Global _ftp_24$ = "myserver.net" // server
Global _Systemftp2$ = "web36f2" // user
Global _axess2012di$ = "abcdefgh123" // pw
Everyone can read this variables simply in the exe file when load into a text editor. I have some solutions for the issue contains Xlate and Crypt.
Global _Systemftp2$ = "web36f2" // user
Global _axess2012di$ = "abcdefgh123" // pw
Everyone can read this variables simply in the exe file when load into a text editor. I have some solutions for the issue contains Xlate and Crypt.
Function FTP_ReceiveFile(ByVal FileName_OnServer$, ByVal FileName$) As Int
Dim TimeOutKB% = 0
Dim TimeOutKBCount% = 0
Dim TimeOutKBCount_OLD% = 0
FileName_OnServer$ = Lower$(FileName_OnServer$)
FTP_MessageInfo.Caption = "Empfange: " + FileName_OnServer$ // ULWADD_TextOut(FTP_MessageInfo.Caption)
''' Message die vom der FTP.dll kommt definieren '''
Local Int Msg = 77777
''' Wir möchten eine Rückmeldung und rufen das Laden selber auf '''
Local BNotify = True
Dim Success As Byte
Local Tmp$ = TempDir$ + "~SSL" + Str$(Random(999999)) + ".tmp"
Success = FtpSetNewSlices(10, 10)
FTP_StartTraceInfo("SLIC 10, 10 " & Success)
''' Daten Flag vorbereiten '''
''' Somit können wir das Senden auch abbrechen '''
Dim pretime% = 0
Success = FtpSetPassiveMode(True)
FTP_StartTraceInfo("PASV " & Success)
Success = FtpRecvFile(FileName_OnServer$, Tmp$, Asc(TYPE_I$), BNotify, FTP_Transfer.hWnd, Msg)
FTP_StartTraceInfo("RECV " & FileName_OnServer$ & ", " & Tmp$ & ", " & TYPE_I$ & ", " & BNotify & ", " & FTP_Transfer.hWnd & ", " & Msg & " " & Success)
//HDDDL
If Success = FTPERR_OK
Dim t As Int64
Dim TotalFileSize% = FtpBytesToBeTransferred()
FTP_StartTraceInfo("BYTES " & TotalFileSize%)
''' Datei Existiert nicht oder ist = 0 Bytes lang '''
If FTP_WantDialoge%
FTP_Pro1.Value = 0
FTP_Pro1.Min = 0
FTP_Pro1.Max = TotalFileSize% + 1
EndIf
FTP_TransferDone% = False
''' Der FTP.Dll Zeit zum verarbeiten übermitteln und so lange warten bis fertig '''
FTP_KBs.Caption = "0.0 KB/s"
t = oTimer
Dim kbs% = 0, tot As Double, cur As Double
Do
' If oTimer - t => 200
pretime% = (oTimer - t)
If FTP_WantDialoge%
FTP_TransferKBSec = (FTP_TransferBytesCurrent%) / (pretime% + 0.00001)
FTP_KBs.Caption = Format$(FTP_TransferKBSec, "####0.#0;;") + " KB/s"
EndIf
If FTP_WantDialoge%
tot = TotalFileSize% / 1024
cur = FTP_TransferBytesCurrent% / 1024
If (tot) => 1000
tot = tot / 1000
cur = cur / 1000
FTP_FileInfo.Caption = Format$(cur, "#######0.#0;;") & " MB von " & Format$(tot, "########0.#0;;") & " MB übertragen..."
Else
FTP_FileInfo.Caption = Format$(cur, "########0.#0;;") & " KB von " & Format$(tot, "########0.#0;;") & " KB übertragen..."
EndIf
FTP_FileInfo.Refresh
FTP_Pro1.Value = FTP_TransferBytesCurrent%
EndIf
DoEvents
Loop Until FTP_TransferDone%
''' Fehler aufgetreten ? '''
If FTP_TransferError% = FTPERR_NOREMOTEFILE
''' File Does not exist on server '''
If Exist(Tmp$)
Kill Tmp$
EndIf
Return FTPERR_NOREMOTEFILE
EndIf
If FTP_TransferError%
If Exist(Tmp$)
Kill Tmp$
EndIf
FTP_StartTraceInfo("***FAIL RECV " & FileName_OnServer$ & " " & FileName$ & " " & FTP_TransferError%)
Return FTP_TransferError%
Else
''' Wurde die Datei auch angelegt? '''
''' Nur wenn die angelegt wurde, zum ziel kopieren '''
If Exist(Tmp$)
Try
FileCopy Tmp$ To FileName$
Kill Tmp$
Catch
FTP_StartTraceInfo("***FAIL Die lokale Datei: " + Tmp$ + " konnte nicht nach " + FileName$ + " kopiert werden " & Success)
EndCatch
Else
FTP_StartTraceInfo("***FAIL Die lokale Datei: " + Tmp$ + " existiert nicht! RECV: Error: " & FileName_OnServer$ & " " & FileName$ & " " & Success)
EndIf
EndIf
FTP_Pro1.Value = TotalFileSize% + 2
Return FTPERR_OK
Else
If Exist(Tmp$)
Kill Tmp$
EndIf
FTP_StartTraceInfo("***FAIL RECV " & FileName_OnServer$ & " " & FileName$ & " " & Success)
Return Success
End If
EndFunction