B4i Library iNMSSH - SFTP file transfer

iNMSSH is based on NMSSH open source library: https://github.com/NMSSH/NMSSH

It implements the SFTP protocol.
Usage example:
B4X:
Private ssh As NMSSH 'Process globals

'initialize
ssh.Initialize("ssh")
'connect
ssh.Connect("100.222.222.222", 22, "username")
Wait For ssh_Connected (success As Boolean)
If success Then
   Log("connected")
   'authenticate
   ssh.Authenticate("password")
   Wait For ssh_Authorized (success As Boolean)
   If success Then
       'file transfer operations
       ssh.List("/")
       Wait For ssh_ListCompleted (success As Boolean, Folders As List, Files As List)
       If success Then
           For Each f As SFtpEntry In Files
               Log($"${f.Name}: $DateTime{f.Timestamp}, ${f.Size}"$)
           Next
       End If
       ssh.DownloadFile("/somefile", File.DirDocuments, "1.txt")
       Wait For ssh_DownloadCompleted (success As Boolean)
       If success Then
           'Log(File.ReadString(File.DirDocuments, "1.txt"))
       End If
       ssh.UploadFile(File.DirAssets, "1.bil", "/1.bil")
       Wait For ssh_UploadCompleted (success As Boolean)
       Log("upload: " & success)
       ssh.DeleteFile("/1.bil")
       Wait For ssh_DeleteCompleted (success As Boolean)
       Log(success)
   End If
End If
'close when done
ssh.Close

There could only be a single NMSSH object.



Mac builder files: www.b4x.com/b4i/files/iNMSSH.zip
 

Attachments

  • iNMSSH.xml
    5.5 KB · Views: 30
Top