B4J Question sftp Problem

kohlenach

Member
I use the JSch library. In the lib list it shows version 1.30 . B4J is v9.8 , Windows 10 Desktop, 64bit
But nothing happen when I try to upload a file. No error nothing. It works with filezilla and other ftp clients. Port 2222 is correct.

The log says :
Waiting for debugger to connect...
Program started.




B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Dim sftp1 As SFtp
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    sftp1.Initialize("sftp1", "xxxxx", "xxxxx", "xxxxxx", 2222)
    sftp1.SetKnownHostsStore(File.DirApp, "hosts.txt")

    MainForm.Show
End Sub

Sub Button1_Click
    'xui.MsgboxAsync("Hello World!", "B4X")
    sftp1.UploadFile(File.DirApp,"1001_1.pdf","/test.pdf")
End Sub




Sub sftp1_PromptYesNo (Message As String)
   Dim res As Int = fx.Msgbox2(MainForm,Message, "", "Yes", "", "No",Null)
   'The next line might be a bit confusing. It is a condition.
   'The value will be True if res equals to DialogResponse.POSITIVE.
   sftp1.SetPromptResult(res = fx.DialogResponse.POSITIVE)
 
   'sftp1.SetPromptResult(True)
End Sub

Sub sftp1_ShowMessage (Message As String)
   fx.Msgbox(MainForm,Message, "")
End Sub

Sub sftp1_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim s As String
    s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
    Log(s)
End Sub

Sub sftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then Log(LastException.Message)
End Sub
 

kohlenach

Member
I changed the code like this, added the sftp1_CommandCompleted event
and the sftp1.GetCurrentPath .
Nothing happens until I click on the button and try to upload file. I get the following error now:

Waiting for debugger to connect...
Program started.
java.lang.NullPointerException
at anywheresoftware.b4a.objects.SFtpWrapper$1.run(SFtpWrapper.java:118)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
/test.pdf, Success=false
java.lang.NullPointerException



B4X:
#Region Project Attributes
    #MainFormWidth: 600
    #MainFormHeight: 600
#End Region

Sub Process_Globals
    Private fx As JFX
    Private MainForm As Form
    Private xui As XUI
    Private Button1 As B4XView
    Dim sftp1 As SFtp
End Sub

Sub AppStart (Form1 As Form, Args() As String)
    MainForm = Form1
    MainForm.RootPane.LoadLayout("Layout1")
    sftp1.Initialize("sftp1", "xxx", "xxxx", "test.com", 2222)
    sftp1.SetKnownHostsStore(File.DirApp, "hosts.txt")
    
    sftp1.GetCurrentPath
    
    MainForm.Show
End Sub

Sub Button1_Click
    'xui.MsgboxAsync("Hello World!", "B4X")
    sftp1.UploadFile(File.DirApp,"1001_1.pdf","/test.pdf")
End Sub

Sub sftp1_CommandCompleted (Command As String, Success As Boolean, ReplyCode As Int, ReplyString As String)
    Log ("command=" & Command)
    Log ("success=" & Success)
    Log ("replyCODE=" & ReplyCode)
    Log ("replystring=" & ReplyString)
    
End Sub


Sub sftp1_PromptYesNo (Message As String)
   Dim res As Int = fx.Msgbox2(MainForm,Message, "", "Yes", "", "No",Null)
   'The next line might be a bit confusing. It is a condition.
   'The value will be True if res equals to DialogResponse.POSITIVE.
   sftp1.SetPromptResult(res = fx.DialogResponse.POSITIVE)
  
   'sftp1.SetPromptResult(True)
End Sub

Sub sftp1_ShowMessage (Message As String)
   fx.Msgbox(MainForm,Message, "")
End Sub

Sub sftp1_UploadProgress (ServerPath As String, TotalUploaded As Long, Total As Long)
    Dim s As String
    s = "Uploaded " & Round(TotalUploaded / 1000) & "KB"
    If Total > 0 Then s = s & " out of " & Round(Total / 1000) & "KB"
    Log(s)
End Sub

Sub sftp1_UploadCompleted (ServerPath As String, Success As Boolean)
    Log(ServerPath & ", Success=" & Success)
    If Success = False Then Log(LastException.Message)
End Sub
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
try to use release build.
run the code and watch the log (maybe the unfiltered log). Looks like the lastexception is not set. It can happen if the error happens in another layer...
 
Upvote 0

kohlenach

Member
I tried the release buil, but the same. But I dont see in B4J the option to see an unfiltered log.
See screenshot. Was there not checkbox with a filter option ?
 

Attachments

  • 25-08-_2022_10-27-52.png
    25-08-_2022_10-27-52.png
    24.3 KB · Views: 144
Upvote 0

kohlenach

Member
I added a sftp1.list("/") before the sftp1.getcurrentpath
and get now the following errors:

Waiting for debugger to connect...
Program started.
java.lang.NullPointerException
at anywheresoftware.b4a.objects.SFtpWrapper$2.run(SFtpWrapper.java:191)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
An error occurred:
(Line: 30) 30
java.lang.Exception: Sub sftp1_commandcompleted signature does not match expected signature.
public static anywheresoftware.b4a.pc.RemoteObject b4j.example.main_subs_0._sftp1_commandcompleted(anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject,anywheresoftware.b4a.pc.RemoteObject) throws java.lang.Exception
class anywheresoftware.b4a.pc.RemoteObject, class anywheresoftware.b4a.pc.RemoteObject, class anywheresoftware.b4a.pc.RemoteObject,
 
Upvote 0
Top