66import android .net .Uri ;
77import android .util .Log ;
88import androidx .documentfile .provider .DocumentFile ;
9- import com .sshtools .client .PublicKeyAuthenticator ;
109import com .sshtools .client .SshClient ;
10+ import com .sshtools .client .SshClient .SshClientBuilder ;
1111import com .sshtools .client .sftp .SftpClient ;
12+ import com .sshtools .client .sftp .SftpClient .SftpClientBuilder ;
1213import com .sshtools .client .sftp .SftpFile ;
1314import com .sshtools .client .sftp .TransferCancelledException ;
1415import com .sshtools .common .permissions .PermissionDeniedException ;
@@ -51,6 +52,7 @@ public void initialize(CordovaInterface cordova, CordovaWebView webView) {
5152 super .initialize (cordova , webView );
5253 context = cordova .getContext ();
5354 activity = cordova .getActivity ();
55+ System .setProperty ("maverick.log.nothread" , "true" );
5456 }
5557
5658 public boolean execute (
@@ -91,10 +93,18 @@ public void run() {
9193 int port = args .optInt (1 );
9294 String username = args .optString (2 );
9395 String password = args .optString (3 );
94- ssh = new SshClient (host , port , username , password .toCharArray ());
96+ ssh = SshClientBuilder .create ()
97+ .withHostname (host )
98+ .withPort (port )
99+ .withUsername (username )
100+ .withPassword (password )
101+ .build ();
102+
95103 if (ssh .isConnected ()) {
96104 connectionID = username + "@" + host ;
97- sftp = new SftpClient (ssh );
105+
106+ sftp = SftpClientBuilder .create ().withClient (ssh ).build ();
107+
98108 try {
99109 sftp .getSubsystemChannel ().setCharsetEncoding ("UTF-8" );
100110 } catch (UnsupportedEncodingException | SshException e ) {
@@ -139,22 +149,18 @@ public void run() {
139149 Uri uri = file .getUri ();
140150 ContentResolver contentResolver = context .getContentResolver ();
141151 InputStream in = contentResolver .openInputStream (uri );
142- SshKeyPair pair = SshKeyUtils .getPrivateKey (in , passphrase );
143-
144- try {
145- pair = SshKeyUtils .makeRSAWithSHA256Signature (pair );
146- pair = SshKeyUtils .makeRSAWithSHA512Signature (pair );
147- } catch (Exception e ) {
148- // ignore
149- }
150-
151- ssh = new SshClient (host , port , username );
152152
153- ssh .authenticate (new PublicKeyAuthenticator (pair ), 30000 );
153+ ssh = SshClientBuilder .create ()
154+ .withHostname (host )
155+ .withPort (port )
156+ .withUsername (username )
157+ .withIdentities (SshKeyUtils .getPrivateKey (in , passphrase ))
158+ .build ();
154159
155160 if (ssh .isConnected ()) {
156161 connectionID = username + "@" + host ;
157- sftp = new SftpClient (ssh );
162+ sftp = SftpClientBuilder .create ().withClient (ssh ).build ();
163+
158164 try {
159165 sftp .getSubsystemChannel ().setCharsetEncoding ("UTF-8" );
160166 } catch (UnsupportedEncodingException | SshException e ) {
@@ -190,7 +196,6 @@ public void run() {
190196 try {
191197 String command = args .optString (0 );
192198 if (ssh != null ) {
193- callback .success ("hiiii" );
194199 JSONObject res = new JSONObject ();
195200 StringBuffer buffer = new StringBuffer ();
196201 int code = ssh .executeCommandWithResult (command , buffer );
@@ -331,21 +336,23 @@ public void run() {
331336 if (filename .equals ("." ) || filename .equals (".." )) {
332337 continue ;
333338 }
334- SftpFileAttributes fileAttributes = file .getAttributes ();
339+ SftpFileAttributes fileAttributes = file .attributes ();
335340 JSONObject fileInfo = new JSONObject ();
336341 fileInfo .put ("name" , filename );
337342 fileInfo .put ("exists" , true );
338- fileInfo .put ("canRead" , file .canRead ());
339- fileInfo .put ("canWrite" , file .canWrite ());
340343
341344 if (fileAttributes != null ) {
342- String permissions = fileAttributes .getPermissionsString ();
345+ String permissions = fileAttributes .toPermissionsString ();
346+ boolean canRead = permissions .charAt (1 ) == 'r' ;
347+ boolean canWrite = permissions .charAt (2 ) == 'w' ;
348+ fileInfo .put ("canRead" , canRead );
349+ fileInfo .put ("canWrite" , canWrite );
343350 fileInfo .put ("permissions" , permissions );
344- fileInfo .put ("length" , fileAttributes .getSize ());
351+ fileInfo .put ("length" , fileAttributes .size ());
345352 fileInfo .put ("url" , file .getAbsolutePath ());
346353 fileInfo .put (
347354 "lastModified" ,
348- fileAttributes .getModifiedDateTime ()
355+ fileAttributes .lastModifiedTime ()
349356 );
350357
351358 if (permissions .charAt (0 ) == 'l' ) {
@@ -405,7 +412,7 @@ public void run() {
405412 try {
406413 SftpFileAttributes fileAttributes = sftp .stat (uri .getPath ());
407414 if (fileAttributes != null ) {
408- String permissions = fileAttributes .getPermissionsString ();
415+ String permissions = fileAttributes .toPermissionsString ();
409416 boolean canRead = permissions .charAt (1 ) == 'r' ;
410417 boolean canWrite = permissions .charAt (2 ) == 'w' ;
411418
@@ -415,14 +422,14 @@ public void run() {
415422 fileStat .put ("isLink" , fileAttributes .isLink ());
416423 fileStat .put ("isDirectory" , fileAttributes .isDirectory ());
417424 fileStat .put ("isFile" , fileAttributes .isFile ());
418- fileStat .put ("length" , fileAttributes .getSize ());
425+ fileStat .put ("length" , fileAttributes .size ());
419426 fileStat .put (
420427 "permissions" ,
421- fileAttributes .getPermissionsString ()
428+ fileAttributes .toPermissionsString ()
422429 );
423430 fileStat .put (
424431 "lastModified" ,
425- fileAttributes .getModifiedDateTime ()
432+ fileAttributes .lastModifiedTime ()
426433 );
427434 String [] pathSegments = uri .getPath ().split ("/" );
428435 String filename = pathSegments [pathSegments .length - 1 ];
0 commit comments