Page 1 of 2
Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 8:11 am
by MichaelS
Hello,
does anybody know how is it possible to show Directory List via SFTP ?
Later I want to put the file List on a DataGrid, and pick the hilited Line to upload/download Files from my Raspberry.
I have a Indy License...
Code: Select all
local tResult, tCmds
put "ls" into tCmds
put tsNetSendCmd("1", "sftp://pi:Wuppertal2019@192.168.178.31", tCmds,"transferComplete") into tResult
put tResult into fld "Ausgabe"
tsNetCloseConn "1"
This gives the Error : tsnetError: Not initialised
Can anybody help me to find a solution?
Regards
Michael
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 3:00 pm
by FourthWorld
Can you log onto the remote machine in Terminal with SSH?
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 4:29 pm
by MichaelS
Yes, offcourse i can !
Do you have any Idea?
Michael
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 4:34 pm
by SparkOut
You do have to run the command tsNetInit to initialise it. I don't see that in your script sample. If you add it, is that the simple answer?
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 5:31 pm
by MichaelS
Hello again,
i added the init Code :
Code: Select all
on mouseUp
local tResult, tCmds
put "ls" into tCmds
tsNetInit
put tsNetSendCmd("1", "ftp://pi:Wuppertal2019@192.168.178.31", tCmds,"transferComplete") into tResult
answer the result
put tResult into fld "Ausgabe"
tsNetCloseConn "1"
end mouseUp
it is opening the answer window without text, and there ist nothing on the field "Ausgabe"
Is there another Possibility to get the file List ?
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 5:44 pm
by matthiasr
Michael,
Although the dictionary shows both tsNetSendCmdSync and tsNetSendCmd to be available in Indy license.
My understanding was that only the synchronous commands/functions (if 2 similar command/functions are available) of tsNet were available in Indy license. I could be wrong, but could you try tsNetSendCmdSync instead of tsNetSendCMD.
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 6:36 pm
by MichaelS
Hi Matthias,
i changed the tsnet command to tsNetSendCmdSync . The Result is :
execution error at line n/a (External handler execution error: parameter 'pBytes' is not a variable) near "parameter 'pBytes' is not a variable"
I do not know what i have to change in this Expression...
Regards
Michael
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 6:45 pm
by matthiasr
The parameters for the sync one are not the same.
tsNetSendCmd(pConnectionID, pURL, pCommand, pCallback, [pSettings])
tsNetSendCmdSync(pURL, pCommand, rResult, rBytes, [pSettings])
So in your case you should try this:
put "pi" into pSettings["username"]
put "Wuppertal2019" into pSettings["password"]
tsNetSendCmdSync( "
ftp://192.168.178.31", tCMDs, rResult, rBytes, pSettings)
What i noticed... Your topic is saying "...via SFTP". But your URL begins with ftp:. So your code is always trying to connect using ftp.
If you want to connect to a sftp server you have to change ftp:// to sftp:// in your URL.
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 6:57 pm
by matthiasr
Btw a simple
Code: Select all
put url "sftp://pi:Wuppertal2019@192.168.178.3/"
should give you also the file listing.
You can even add foldernames
Code: Select all
put url "sftp://pi:Wuppertal2019@192.168.178.3/public_html/"
And of course, if your ftp/sftp server is running on an other port than 21(ftp) / 22 (sftp) then you have to add the port also to the URL.
For example
Code: Select all
put url "sftp://pi:Wuppertal2019@192.168.178.3:8228/public_html/"
Re: Get FileList on Remote PC via SFTP
Posted: Sun May 24, 2020 7:59 pm
by SparkOut
I realise that there is nothing in this thread that specifically identifies a public site and credentials, but... you really shouldn't use the real password on a public forum, and I feel that even if it is a raspbi pi on a private network, the live server should have the password changed nevertheless.
Re: Get FileList on Remote PC via SFTP
Posted: Mon May 25, 2020 7:41 am
by MichaelS
Good morning,
@Sparkout : The Raspi is not reachable extern, it is only to Test the sftp-Connection. The Code will be used to Connect an Android System with my rented Root Server, and i will not make public this Passwords. But Thanks for the Tip.
@ matthiasr : (Sorry for changing Sftp with ftp, i tried everything out)
This Code is not Working ; no Result, no Output:
Code: Select all
put url "sftp://pi:Wuppertal2019@192.168.178.31/" into Ausgabe
answer the result
put Ausgabe into fld"Ausgabe"
The following Code is working as expected :
Code: Select all
put url "sftp://pi:Wuppertal2019@192.168.178.31/home/pi/Notiz.txt" into Ausgabe
answer the result
put Ausgabe into fld"Ausgabe"
At least i tried this :
Code: Select all
local rResult, tCmds, rBytes, pSettings
put "ls" into tCmds
tsNetInit
put "pi" into pSettings["username"]
put "Wuppertal2019" into pSettings["password"]
tsNetSendCmdSync( "sftp://192.168.178.31", tCMDs, rResult, rBytes, pSettings)
answer the result
put rResult into fld "Ausgabe"
tsNetCloseConn "1"
This is similar like the sample in the Dictionary and should work with Indy Licence.
But I got this Error :
execution error at line 7 (Handler: can't find handler) near "tsNetSendCmdSync", char 1
What does it mean "Can not find Handler ? Where is my Mistake ?
Re: Get FileList on Remote PC via SFTP
Posted: Mon May 25, 2020 7:46 am
by matthiasr
I am not sure if that is the problem, but there is a blank between
( and
"sftp:..../b]
Code: Select all
tsNetSendCmdSync( "sftp://192.168.178.31", tCMDs, rResult, rBytes, pSettings)
Btw. did you try to connect using FTP already? Just to make sure there is no other problem with SFTP?
if not, could you try just
put URL "
ftp://pi:Wuppertal2019@192.168.178.31"
Re: Get FileList on Remote PC via SFTP
Posted: Mon May 25, 2020 8:47 am
by matthiasr
MichaelS wrote: ↑Mon May 25, 2020 7:41 am
At least i tried this :
Code: Select all
local rResult, tCmds, rBytes, pSettings
put "ls" into tCmds
tsNetInit
put "pi" into pSettings["username"]
put "Wuppertal2019" into pSettings["password"]
tsNetSendCmdSync( "sftp://192.168.178.31", tCMDs, rResult, rBytes, pSettings)
answer the result
put rResult into fld "Ausgabe"
tsNetCloseConn "1"
I just realize that you are calling tsNetSendCmdSync wrong. It´s a function, so your code should look something like this.
Code: Select all
local rResult, tCmds, rBytes, pSettings
put "ls" into tCmds
tsNetInit
put "pi" into pSettings["username"]
put "Wuppertal2019" into pSettings["password"]
get tsNetSendCmdSync( "sftp://192.168.178.31", tCMDs, rResult, rBytes, pSettings) -- the var it contains the data
answer the result
put rResult into fld "Ausgabe" -- as dictionary says, will contain 0 for sftp connections or on errors it will contain the tsNet error
rem tsNetCloseConn "1" -- not needed as you are calling the synchronous function
I will test your script later this day with my NAS which is running SFTP server. If there is still something wrong then i will create a sample script.
Re: Get FileList on Remote PC via SFTP
Posted: Mon May 25, 2020 8:49 am
by MichaelS
I removed the Blank between the ( and " , it has no effect.
FTP Connection is although at the Terminal not working.
The Message is : ftp: pi@192.168.178.31: Name or service not known
I tried it in LC out but nothing happen, no Result.
Re: Get FileList on Remote PC via SFTP
Posted: Mon May 25, 2020 9:03 am
by bangkok
Have a look a this sample stack, written by the creator... of tsNet.
https://downloads.techstrategies.com.au ... k.livecode
There are 4 buttons for you :
"SFTP Dir List Example"
"SFTP Delete Example""
"SFTP Upload Example"
"SFTP Download Example