Feature Request - hb_vf* family of functions to respect remote host

88 views
Skip to first unread message

Pritpal Bedi

unread,
Nov 28, 2022, 8:01:10 PM11/28/22
to Harbour Developers
Hi Przemek

Is it possible to apply these functions for remote host like :

hb_vfDirectory( "ro...@10.0.0.12:/data/myfolder/*.dbf" )

Given that ro...@10.0.0.12 is configured to ssh unattended access via 
ssh-copy-id -i ~/.ssh/id_rsa.pub ro...@10.0.0.12.

I know, and is consuming this functionality with NETIO but than that is only possible when NETIO server is installed on th eremote host, which in certain circumstances is not possible.

Regards,

Pritpal Bedi
a student of software analysis and concepts

Przemyslaw Czerpak

unread,
Nov 29, 2022, 8:22:46 AM11/29/22
to harbou...@googlegroups.com
Hi Pritpal,

It's possible but it has to be written from scratch.
ssh should be open in PIPE then command and data written
to this pipe and finally results read.
For file list 'ls -la <dir>/' should be used. To create and remove
directories 'rmdir <dir>' and `mkdir <dir>`. To read and write
whole files `cat - > <file>` and cat <file> is enough.
For sequential reading 'and writing `dd` can be used.
Here the simplest way is using ifs=1 or ofs=1 parameter but
it will be slow so in the final version the requests have to  be
divide, i.e. the first part with bs=1 and size < 4096 to reach
offset with 4096 alignment. Then main part with in 4096 bytes
blocks, finally the last part with bs=1 to read last partial block.
Of course the block size should be optimized  depending on the
total number of bytes written or read.
Locks will not be supported but it's rather obvious in such case.

The other method is writing own server for hb_vf* operations
which is controlled by stdin and stdout. Then we open ssh in
PIPE and run this server. In such case all hb_vf* operations can
be implemented also locks because files can be open and theit
descriptor kept alive till explicit close request.

Unfortunately I do not have time to work on it now.
But you or someone else can try.

best regards,
Przemek

W dniu 29.11.2022 o 02:01, Pritpal Bedi pisze:
--
You received this message because you are subscribed to the Google Groups "Harbour Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to harbour-deve...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/harbour-devel/3d3e4ebe-e588-46a5-81c7-7ba940b596c6n%40googlegroups.com.


Pritpal Bedi

unread,
Nov 29, 2022, 10:49:51 AM11/29/22
to Harbour Developers
Hi Przemek

I needed two function - hb_vfDirectory() and hb_vfCopyFile(). I had implemented them like, little lengthy but is working for me. I put the feature request to simplify the whole process. I believe it is beyond my capabilities to implement them in the core instead of the fact that you provided enough insight how it can be done. 

Thanks you for responding. We know that you are busy with other important tasks.

FUNCTION __pullDirList( cPath, cServer )  
   LOCAL cStdOut, cCmd, aDir, cFile, aFiles, d_, cFileName, cExt
   
   IF ! Empty( cServer )
      cCmd := "ssh " + cServer + " ls " + cPath + " -lAst --full-time"
      hb_processRun( cCmd, NIL, @cStdOut, NIL, .T. )
      IF ! Empty( cStdOut )
         aFiles := hb_ATokens( cStdOut, .T. )
         aDir := {}
         FOR EACH cFile IN aFiles
            cFile := StrTran( cFile, Space( 5 ), " " )
            cFile := StrTran( cFile, Space( 4 ), " " )
            cFile := StrTran( cFile, Space( 3 ), " " )
            cFile := StrTran( cFile, Space( 2 ), " " )
            AAdd( aDir, hb_ATokens( cFile, " " ) )
         NEXT
         IF ! Empty( aDir )
            d_:= {}
            FOR EACH aFiles IN aDir
               IF Len( aFiles ) >= 10
                   // translate to hb_vfDirectory() structure
                  hb_FNameSplit( aFiles[ 10 ], NIL, @cFileName, @cExt )
                  AAdd( d_, { cFileName + cExt, Val( aFiles[ 6 ] ), hb_StrToTS( aFiles[ 7 ] + " " + Left( aFiles[ 8 ], 12 ) ), Left( aFiles[ 8 ], 12 ) } )
               ENDIF
            NEXT
         ENDIF
      ENDIF
   ELSE
      d_:= hb_vfDirectory( cPath )
   ENDIF
   RETURN d_
   

   FUNCTION __takeBackup( cServer, cPath )
   LOCAL cStdOut, cName
   LOCAL hLog := hb_Hash()  
   LOCAL cCmd := "rsync -a " + cServer + ":" + cPath + " /data/backups"
   
   ? cCmd
   ? "Transferring backup .20 to .23 ....", hb_TSToStr( hb_DateTime() )

   hb_processRun( cCmd, NIL, @cStdOut, NIL, .F. )                     // actual

   ? "Finished transfer .................", hb_TSToStr( hb_DateTime() )
   ? cStdOut

   RETURN NIL



Regards

Pritpal Bedi
a student of software analysis and concepts

Lailton Fernando Mariano

unread,
Nov 29, 2022, 7:33:58 PM11/29/22
to Harbour Developers
Hi Pritpal,

Why not implement a ssh function? maybe libssh2 can be useful

Note 100% sure but I think that can work for you.
Reply all
Reply to author
Forward
0 new messages