Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Only God can make random selections.


devel / comp.lang.clipper.visual-objects / Re: SFTP

Re: SFTP

<4adbc412-3664-40b5-bbb7-49fcce0acee6n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=1022&group=comp.lang.clipper.visual-objects#1022

  copy link   Newsgroups: comp.lang.clipper.visual-objects
X-Received: by 2002:a05:620a:4449:: with SMTP id w9mr2434886qkp.458.1642767725600;
Fri, 21 Jan 2022 04:22:05 -0800 (PST)
X-Received: by 2002:a05:620a:25cf:: with SMTP id y15mr2438091qko.21.1642767725228;
Fri, 21 Jan 2022 04:22:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.clipper.visual-objects
Date: Fri, 21 Jan 2022 04:22:05 -0800 (PST)
In-Reply-To: <j4kt9aFa18iU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=84.190.75.203; posting-account=AoONowoAAACH0l2RPl_j6O0JJDlm9SzB
NNTP-Posting-Host: 84.190.75.203
References: <hndhpeFeg3dU1@mid.individual.net> <da8ba5e2-db76-402e-93f6-9e618a0e181bo@googlegroups.com>
<j4dq0cFu1g0U1@mid.individual.net> <00bb65b4-6852-4f9a-9081-70c25d8e6ac2n@googlegroups.com>
<j4kt9aFa18iU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4adbc412-3664-40b5-bbb7-49fcce0acee6n@googlegroups.com>
Subject: Re: SFTP
From: gerhard.bunzel@gmail.com (Gerhard Bunzel)
Injection-Date: Fri, 21 Jan 2022 12:22:05 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 316
 by: Gerhard Bunzel - Fri, 21 Jan 2022 12:22 UTC

Hallo Rüdiger,

nachfolgend etwas Code. Der ist nicht schön - zum Testen sollte das aber funktionieren.
Wichtig ist bei den Events anscheinend der Aufruf von DoEvents() um die Nachrichten zu verarbeiten.
Ich hatte das einfach in einer Schleife getestet. In einer richtigen Sftp-Klasse mit den Funktionen würde das natürlich anders aussehen.
Die Funktionsaufrufe ohne die Verarbeitung der Events - einfach die Befehle nacheinander abarbeiten lassen - ist recht einfach und funktioniert gut.

HTH

Gerhard Bunzel

Die DEFINES:
DEFINE wodSFTP_typeDirectory := 0
DEFINE wodSFTP_typeSymlink := 1
DEFINE wodSFTP_typeFile := 2
DEFINE wodSFTP_typeTemporary := 3
DEFINE wodSFTP_typeUnknown := 4
// DirItemTypes

DEFINE wodSFTP_ZoneLocal := 0
DEFINE wodSFTP_ZoneUTC := 1
// TimezonesEnum

DEFINE wodSFTP_Binary := 0
DEFINE wodSFTP_AscII := 1
// TransferModesEnum

DEFINE wodSFTP_PermRead := 1
DEFINE wodSFTP_PermWrite := 2
DEFINE wodSFTP_PermCreate := 4
DEFINE wodSFTP_PermTruncate := 8
// RemotePermissions

DEFINE wodSFTP_Disconnected := 0
DEFINE wodSFTP_Connecting := 1
DEFINE wodSFTP_LogonInProgress := 2
DEFINE wodSFTP_Connected := 3
DEFINE wodSFTP_Receiving := 4
DEFINE wodSFTP_Sending := 5
DEFINE wodSFTP_Executing := 6
DEFINE wodSFTP_AccessingRawFile := 7
// StatesEnum

DEFINE wodSFTP_encAny := 0
DEFINE wodSFTP_encDES := 1
DEFINE wodSFTP_enc3DES := 2
DEFINE wodSFTP_encAES := 3
DEFINE wodSFTP_encBLOWFISH := 4
DEFINE wodSFTP_encAES128 := 5
DEFINE wodSFTP_encAES192 := 6
DEFINE wodSFTP_encAES256 := 7
DEFINE wodSFTP_encCAST128 := 8
DEFINE wodSFTP_encAEScbc := 9
DEFINE wodSFTP_encAESctr := 10
// EncryptionsEnum

DEFINE wodSFTP_authBoth := 0
DEFINE wodSFTP_authPassword := 1
DEFINE wodSFTP_authPubkey := 2
DEFINE wodSFTP_authSecurID := 3
DEFINE wodSFTP_authKeyboardInteractive := 4
DEFINE wodSFTP_authGSSAPI := 5
// AuthenticationsEnum

DEFINE wodSFTP_ProxyNone := 0
DEFINE wodSFTP_ProxySocks4 := 1
DEFINE wodSFTP_ProxySocks5 := 2
DEFINE wodSFTP_ProxyWEBStandard := 3
DEFINE wodSFTP_ProxyRelay := 4
DEFINE wodSFTP_ProxySocks4a := 5
DEFINE wodSFTP_ProxyWEBNtlmAuth := 6
DEFINE wodSFTP_ProxyWEBIntegratedAuth := 8
// ProxyTypes

Die DLL-Functions - nicht vollständig und auch nicht jede Funktion komplett getestet. Die fehlenden Funktionen können damit aber bestimmt selbst erstellt werden.
_DLL FUNCTION Sftp_Create (ptrSftpEventsStruct AS PTR, pszLicenseKey AS PSZ) AS PTR PASCAL:SftpDLL.Sftp_Create
_DLL FUNCTION Sftp_Destroy (ptrSftpDLL AS PTR) AS VOID PASCAL:SftpDLL.Sftp_Destroy
_DLL FUNCTION Sftp_Disconnect (ptrSftpDLL AS PTR) AS LONG PASCAL:SftpDLL.Sftp_Disconnect
_DLL FUNCTION Sftp_GetMyHostname (ptrSftpDLL AS PTR, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetMyHostname
_DLL FUNCTION Sftp_GetMyIP (ptrSftpDLL AS PTR, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetMyIP
_DLL FUNCTION Sftp_GetVersion (ptrSftpDLL AS PTR, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetVersion
_DLL FUNCTION Sftp_GetBlocking (ptrSftpDLL AS PTR, lValue REF LOGIC) AS LONG PASCAL:SftpDLL.Sftp_GetBlocking
_DLL FUNCTION Sftp_SetBlocking (ptrSftpDLL AS PTR, lValue AS LOGIC) AS LONG PASCAL:SftpDLL.Sftp_SetBlocking
_DLL FUNCTION Sftp_SetHostname (ptrSftpDLL AS PTR, pszBuffer AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_SetHostname
_DLL FUNCTION Sftp_GetPort (ptrSftpDLL AS PTR, nPort REF DWORD) AS LONG PASCAL:SftpDLL.Sftp_GetPort
_DLL FUNCTION Sftp_SetPort (ptrSftpDLL AS PTR, nPort AS DWORD) AS LONG PASCAL:SftpDLL.Sftp_SetPort
_DLL FUNCTION Sftp_SetLogin (ptrSftpDLL AS PTR, pszBuffer AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_SetLogin
_DLL FUNCTION Sftp_Connect (ptrSftpDLL AS PTR) AS LONG PASCAL:SftpDLL.Sftp_Connect
_DLL FUNCTION Sftp_SetPassword (ptrSftpDLL AS PTR, pszBuffer AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_SetPassword
_DLL FUNCTION Sftp_ListAttributes ( ptrSftpDLL AS PTR, pszRemotePath AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_ListAttributes
_DLL FUNCTION Sftp_GetListItem (ptrSftpDLL AS PTR, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetListItem
_DLL FUNCTION Sftp_PutFile (ptrSftpDLL AS PTR, pszLocalFile AS PSZ, pszRemotePath AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_PutFile
_DLL FUNCTION Sftp_GetFile (ptrSftpDLL AS PTR, pszLocalFile AS PSZ, pszRemoteFile AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_GetFile
_DLL FUNCTION Sftp_GetRemotePath (ptrSftpDLL AS PTR, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetRemotePath
_DLL FUNCTION Sftp_SetRemotePath (ptrSftpDLL AS PTR, pszNewPath AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_SetRemotePath
_DLL FUNCTION Sftp_GetLocalPath (ptrSftpDLL AS PTR, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetLocalPath
_DLL FUNCTION Sftp_SetLocalPath (ptrSftpDLL AS PTR, pszNewPath AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_SetLocalPath
_DLL FUNCTION Sftp_GetClientName (ptrSftpDLL AS PTR, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetClientName
_DLL FUNCTION Sftp_SetClientName (ptrSftpDLL AS PTR, pszNewClient AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_SetClientName
_DLL FUNCTION Sftp_MakeDir (ptrSftpDLL AS PTR, pszRemotePath AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_MakeDir
_DLL FUNCTION Sftp_DeleteFile (ptrSftpDLL AS PTR, pszRemoteFile AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_DeleteFile
_DLL FUNCTION Sftp_Abort (ptrSftpDLL AS PTR) AS LONG PASCAL:SftpDLL.Sftp_Abort
_DLL FUNCTION Sftp_GetState (ptrSftpDLL AS PTR, nState REF DWORD) AS LONG PASCAL:SftpDLL.Sftp_GetState
_DLL FUNCTION Sftp_GetStateText (ptrSftpDLL AS PTR, nState AS DWORD, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetStateText
_DLL FUNCTION Sftp_GetErrorText (ptrSftpDLL AS PTR, nErrorCode AS SHORT, pszBuffer AS PSZ, nSize REF LONG) AS LONG PASCAL:SftpDLL.Sftp_GetErrorText
_DLL FUNCTION Sftp_GetLastError (ptrSftpDLL AS PTR, nErrorCode REF SHORT) AS LONG PASCAL:SftpDLL.Sftp_GetLastError
_DLL FUNCTION Sftp_SetTransferMode((ptrSftpDLL AS PTR, nValue AS SHORT) AS LONG PASCAL:SftpDLL.Sftp_SetTransferMode
_DLL FUNCTION Sftp_ListNames ( ptrSftpDLL AS PTR, pszRemotePath AS PSZ) AS LONG PASCAL:SftpDLL.Sftp_ListNames

Die Structure für die Events:
STRUCT SftpEventsStruct
MEMBER hConnected AS PTR
MEMBER hDisconnected AS PTR
MEMBER hStateChange AS PTR
MEMBER hHostFingerprint AS PTR
MEMBER hProgress AS PTR
MEMBER hListItems AS PTR
MEMBER hDone AS PTR
MEMBER hAttributes AS PTR
MEMBER hCryptoInformation AS PTR
MEMBER hAttributesData AS PTR
MEMBER hLoginChallenge AS PTR
MEMBER hLoopItem AS PTR
MEMBER hLoopError AS PTR
MEMBER hRemoteData AS PTR
MEMBER hExtendedCmdReply AS PTR

Die Prozeduren für den Empfang der Events:
PROCEDURE Sftp_Done (hWnd AS PTR, nErrorCode AS SHORT, pErrorText AS PSZ)
// _dOut(#Sftp_Done, hWnd, nErrorCode, pErrorText)
RETURN

PROCEDURE Sftp_Disconnected (hWnd AS PTR)

// _dOut(#Sftp_Disconnected, hWnd)
RETURN

PROCEDURE Sftp_Connected (hWnd AS PTR, nErrorCode AS SHORT, pErrorText AS PSZ)

// _dOut(#Sftp_Connected, hWnd, nErrorCode, Psz2String(pErrorText))
RETURN

PROCEDURE Sftp_StateChange (hWnd AS PTR, nOldState AS LONG)
// _dOut(#Sftp_StateChange, hWnd, nOldState)
RETURN

PROCEDURE Sftp_Progress (hWnd AS PTR, param1, param2)
// (hWnd AS PTR, nPosition AS I64Rec, nTotal AS I64Rec) AS VOID CALLBACK
// Mit den 64Bit-Parametern noch nicht getestet!!!!

// _dOut(#Sftp_Progress, hWnd, param1, param2)
RETURN

Etwas Code aus meinen Tests. Die Umschaltung zwischen 'normalem Funktionsaufruf' und 'ASync-Modus mit Events' erfolgt mit dem 'Sftp_SetBlocking()' und dem Sftp_Create() mit oder ohne erstem Parameter.

TEXTBLOCK Sample
LOCAL pSftpDLL AS PTR
LOCAL pBuf1, pBuf2 AS PSZ
LOCAL i, nCount AS INT
LOCAL nState AS DWORD
LOCAL nRet AS LONG
LOCAL cRet AS STRING
LOCAL nError AS SHORT
// LOCAL lRet AS LOGIC
LOCAL pEvent IS SftpEventsStruct

// LOCAL struFindData IS _winWIN32_FIND_DATA

nCount := 0
pEvent.hConnected := @Sftp_Connected ()
pEvent.hDisconnected := @Sftp_Disconnected ()
pEvent.hDone := @Sftp_Done ()
pEvent.hStateChange := @Sftp_StateChange ()
pEvent.hProgress := @Sftp_Progress ()
// pSftpDLL := Sftp_Create(NULL_PTR, String2Psz("LizenzKey"))
pSftpDLL := Sftp_Create(@pEvent, String2Psz("LizenzKey"))
pBuf1 := MemAlloc(10240)
pBuf2 := MemAlloc(1024)
MemSet(pBuf1, 0, 10240)
MemSet(pBuf2, 0, 1024)
i := 1024
nRet := Sftp_GetMyIP(pSftpDLL, pBuf2, @i)
cRet := Psz2String(pBuf2)
nRet := Sftp_GetMyHostname(pSftpDLL, pBuf2, @i)
cRet := Psz2String(pBuf2)
// Test zum Setzen und Lesen von Sftp_SetBlocking()
// nRet := Sftp_SetBlocking(pSftpDLL, TRUE)
// nRet := Sftp_GetBlocking(pSftpDLL, @lRet)
nRet := Sftp_SetBlocking(pSftpDLL, FALSE)
// nRet := Sftp_GetBlocking(pSftpDLL, @lRet)
// nRet := Sftp_SetBlocking(pSftpDLL, TRUE)
nRet := Sftp_SetHostname(pSftpDLL, String2Psz("www.MyServer.com"))
nRet := Sftp_SetLogin(pSftpDLL, String2Psz("MyTest"))
i := 1024
nRet := Sftp_GetVersion(pSftpDLL, pBuf2, @i)
cRet := Psz2String(pBuf2)
nRet := Sftp_SetPassword(pSftpDLL, String2Psz("MyPassword"))
nRet := Sftp_SetPort(pSftpDLL, 202)
// Status abfragen
nRet := Sftp_GetState(pSftpDLL, @nState)
i := 1024
nRet := Sftp_GetStateText(pSftpDLL, nState, pBuf2, @i)
cRet := Psz2String(pBuf2)
nRet := Sftp_GetLastError(pSftpDLL, @nError)
i := 1024
nRet := Sftp_GetErrorText(pSftpDLL, nError, pBuf2, @i)
_dOut(pBuf2)
i := Sftp_Connect(pSftpDLL)

// Eine Schleife um die Events zu testen.
DO WHILE nCount <= 100
// nRet := Sftp_GetState(pSftpDLL, @nState)
// _dOut(nState)
// IF nState==3
// EXIT
// ENDIF
// ApplicationExec(EXECWHILEEVENT)
DoEvents()
Sleep(100)
nCount++
ENDDO
nRet := Sftp_GetState(pSftpDLL, @nState)
_dOut(nState)
IF nState == 3
// IF i == 0
nRet := Sftp_GetState(pSftpDLL, @nState)

nRet := Sftp_ListAttributes(pSftpDLL, String2Psz("/home/longtest"))
i := 10240
nRet := Sftp_GetListItem(pSftpDLL, pBuf1, @i)
_dOut(pBuf1)
SaveFile("sftp_dir_1.txt", Psz2String(pBuf1))

nRet := Sftp_PutFile(pSftpDLL, String2Psz("C:\MyTest\TestFile.txt"), String2Psz("/home/longtest"))

nRet := Sftp_ListAttributes(pSftpDLL, String2Psz("/home/longtest"))
i := 10240
nRet := Sftp_GetListItem(pSftpDLL, pBuf1, @i)
_dOut(pBuf1)
SaveFile("sftp_dir_2.txt", Psz2String(pBuf1))
ELSE
nRet := Sftp_GetLastError(pSftpDLL, @nError)
i := 1024
nRet := Sftp_GetErrorText(pSftpDLL, nError, pBuf2, @i)
_dOut(pBuf2)
ENDIF
nRet := Sftp_Disconnect(pSftpDLL)
Sftp_Destroy(pSftpDLL)
MemFree(pBuf1)
MemFree(pBuf2)
RETURN NIL

SubjectRepliesAuthor
o Re: SFTP

By: Rüdiger Fresemann on Fri, 14 Jan 2022

8Rüdiger Fresemann
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor