Last active
May 25, 2024 10:18
Revisions
-
dacr revised this gist
May 25, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ // run-with : scala-cli $file // --------------------- //> using scala "3.4.2" //> using dep "org.apache.sshd:sshd-core:2.8.0" //> using dep "org.apache.sshd:sshd-sftp:2.8.0" //> using dep "org.apache.sshd:sshd-scp:2.8.0" -
dacr revised this gist
May 25, 2024 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ // run-with : scala-cli $file // --------------------- //> using scala "3.4.2" //> using dep "org.apache.sshd:sshd-core:2.8.0" //> using dep "org.apache.sshd:sshd-sftp:2.8.0" //> using dep "org.apache.sshd:sshd-scp:2.8.0" -
dacr revised this gist
Apr 2, 2023 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,18 +2,18 @@ // keywords : scala, ssh, client, server, apache-sshd, mina, @testable // publish : gist // authors : David Crosson // license : Apache NON-AI License Version 2.0 (https://raw.githubusercontent.com/non-ai-licenses/non-ai-licenses/main/NON-AI-APACHE2) // id : a267b427-a378-445c-b91e-e26ddf889c72 // created-on : 2018-07-02T19:35:49Z // managed-by : https://github.com/dacr/code-examples-manager // run-with : scala-cli $file // --------------------- //> using scala "3.1.1" //> using dep "org.apache.sshd:sshd-core:2.8.0" //> using dep "org.apache.sshd:sshd-sftp:2.8.0" //> using dep "org.apache.sshd:sshd-scp:2.8.0" //> using dep "org.slf4j:slf4j-simple:1.7.32" // --------------------- import java.util.concurrent.TimeUnit -
dacr revised this gist
Dec 11, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // keywords : scala, ssh, client, server, apache-sshd, mina, @testable // publish : gist // authors : David Crosson // license : Apache2 BUT Machine Learning models training is not allowed by the author // id : a267b427-a378-445c-b91e-e26ddf889c72 // created-on : 2018-07-02T19:35:49Z // managed-by : https://github.com/dacr/code-examples-manager -
dacr revised this gist
Jul 20, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -6,7 +6,7 @@ // id : a267b427-a378-445c-b91e-e26ddf889c72 // created-on : 2018-07-02T19:35:49Z // managed-by : https://github.com/dacr/code-examples-manager // run-with : scala-cli $file // --------------------- //> using scala "3.1.1" -
dacr revised this gist
Jan 28, 2022 . 1 changed file with 5 additions and 5 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,11 +9,11 @@ // run-with : scala-cli $scriptFile // --------------------- //> using scala "3.1.1" //> using lib "org.apache.sshd:sshd-core:2.8.0" //> using lib "org.apache.sshd:sshd-sftp:2.8.0" //> using lib "org.apache.sshd:sshd-scp:2.8.0" //> using lib "org.slf4j:slf4j-simple:1.7.32" // --------------------- import java.util.concurrent.TimeUnit -
dacr revised this gist
Jan 22, 2022 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -9,7 +9,7 @@ // run-with : scala-cli $scriptFile // --------------------- // using scala 3.1.1 // using lib "org.apache.sshd:sshd-core:2.8.0" // using lib "org.apache.sshd:sshd-sftp:2.8.0" // using lib "org.apache.sshd:sshd-scp:2.8.0" @@ -47,7 +47,7 @@ object Main { sshd.setHost(sshHost) sshd.setPort(sshPort) // first command is the "unparsed one" sshd.setShellFactory(new ProcessShellFactory("/bin/cat", "/bin/cat")) // TODO Take care not always installed at this place sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()) sshd.setPasswordAuthenticator(new PasswordAuthenticator { override def authenticate(username: String, password: String, serverSession: ServerSession): Boolean = { -
dacr revised this gist
Jan 4, 2022 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // summary : SSH server and client operations both within a single script using apache sshd. // keywords : scala, ssh, client, server, apache-sshd, mina, @testable // publish : gist // authors : David Crosson // license : Apache2 -
dacr revised this gist
Jan 4, 2022 . 1 changed file with 16 additions and 9 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,16 +1,20 @@ // summary : SSH server and client operations both within a single script using apache sshd. // keywords : scala, ssh, client, server, apache-sshd, mina // publish : gist // authors : David Crosson // license : Apache2 // id : a267b427-a378-445c-b91e-e26ddf889c72 // created-on : 2018-07-02T19:35:49Z // managed-by : https://github.com/dacr/code-examples-manager // run-with : scala-cli $scriptFile // --------------------- // using scala 3.1.1-RC2 // using lib "org.apache.sshd:sshd-core:2.8.0" // using lib "org.apache.sshd:sshd-sftp:2.8.0" // using lib "org.apache.sshd:sshd-scp:2.8.0" // using lib "org.slf4j:slf4j-simple:1.7.32" // --------------------- import java.util.concurrent.TimeUnit import org.apache.sshd.client.SshClient @@ -42,7 +46,8 @@ object Main { val sshd = SshServer.setUpDefaultServer sshd.setHost(sshHost) sshd.setPort(sshPort) // first command is the "unparsed one" sshd.setShellFactory(new ProcessShellFactory("/usr/bin/cat", "/usr/bin/cat")) sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()) sshd.setPasswordAuthenticator(new PasswordAuthenticator { override def authenticate(username: String, password: String, serverSession: ServerSession): Boolean = { @@ -58,9 +63,11 @@ object Main { session.auth.verify(5, TimeUnit.SECONDS) val channel:ClientChannel = session.createChannel(Channel.CHANNEL_SHELL) val baos = new ByteArrayOutputStream val w = new OutputStreamWriter(baos) w.write("Hello world") //w.flush() w.close() channel.setIn(new ByteArrayInputStream(baos.toByteArray)) @@ -73,8 +80,8 @@ object Main { val result: String = out.toString.trim println(s"-->'$result'") // should print 'id' if the current os has an available "/bin/cat" command assert(result == "Hello world") sshd.stop() } -
dacr revised this gist
Nov 30, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,6 +5,7 @@ // license : Apache2 // id : a267b427-a378-445c-b91e-e26ddf889c72 // created-on : 2018-07-02T19:35:49Z // managed-by : https://github.com/dacr/code-examples-manager // execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' import $ivy.`org.apache.sshd:sshd-core:2.0.0` -
dacr revised this gist
Nov 29, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -4,6 +4,7 @@ // authors : David Crosson // license : Apache2 // id : a267b427-a378-445c-b91e-e26ddf889c72 // created-on : 2018-07-02T19:35:49Z // execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' import $ivy.`org.apache.sshd:sshd-core:2.0.0` -
dacr revised this gist
May 1, 2021 . No changes.There are no files selected for viewing
-
dacr revised this gist
Oct 9, 2020 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,7 +2,7 @@ // keywords : scala, ssh, client, server, apache-sshd // publish : gist // authors : David Crosson // license : Apache2 // id : a267b427-a378-445c-b91e-e26ddf889c72 // execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' -
dacr revised this gist
Oct 3, 2020 . No changes.There are no files selected for viewing
-
dacr revised this gist
Jul 7, 2020 . 1 changed file with 2 additions and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,8 @@ // summary : SSH server and client operations both within a single script using apache sshd. // keywords : scala, ssh, client, server, apache-sshd // publish : gist // authors : David Crosson // license : GPL // id : a267b427-a378-445c-b91e-e26ddf889c72 // execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' -
dacr revised this gist
Sep 11, 2019 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ // publish : gist, snippet // authors : David Crosson // id : a267b427-a378-445c-b91e-e26ddf889c72 // execution : scala ammonite script (http://ammonite.io/) - run as follow 'amm scriptname.sc' import $ivy.`org.apache.sshd:sshd-core:2.0.0` import $ivy.`org.apache.sshd:sshd-sftp:2.0.0` -
dacr revised this gist
Aug 29, 2019 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,7 @@ // summary : SSH server and client operations both within a single script using apache sshd. // keywords : scala, ssh, client, server, apache-sshd // publish : gist, snippet // authors : David Crosson // id : a267b427-a378-445c-b91e-e26ddf889c72 import $ivy.`org.apache.sshd:sshd-core:2.0.0` -
dacr revised this gist
Aug 29, 2019 . 1 changed file with 0 additions and 79 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,79 +0,0 @@ -
dacr revised this gist
Aug 29, 2019 . 1 changed file with 79 additions and 0 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,79 @@ // summary : SSH server and client operations both within a single script using apache sshd. // keywords : ssh, client, server, apache-sshd // publish : gist, snippet // authors : @crodav // id : a267b427-a378-445c-b91e-e26ddf889c72 import $ivy.`org.apache.sshd:sshd-core:2.0.0` import $ivy.`org.apache.sshd:sshd-sftp:2.0.0` import $ivy.`org.apache.sshd:sshd-scp:2.0.0` import java.util.concurrent.TimeUnit import org.apache.sshd.client.SshClient import org.apache.sshd.common.channel.Channel import org.apache.sshd.server.SshServer import org.apache.sshd.server.auth.password.PasswordAuthenticator import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider import org.apache.sshd.server.session.ServerSession import java.io.OutputStreamWriter import org.apache.sshd.client.channel.{ClientChannel, ClientChannelEvent} import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import org.apache.sshd.server.shell.ProcessShellFactory // Everything in a object as soon as we have to deal with futures, promises, asynchronous operations // object Main { val sshHost = "localhost" val sshPort = 2222 val testUsername = "test" val testPassword = "test" def go:Unit = { println("Starting operations") val sshd = SshServer.setUpDefaultServer sshd.setHost(sshHost) sshd.setPort(sshPort) sshd.setShellFactory(new ProcessShellFactory("/bin/cat")) sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()) sshd.setPasswordAuthenticator(new PasswordAuthenticator { override def authenticate(username: String, password: String, serverSession: ServerSession): Boolean = { username==testUsername && password == testPassword } }) sshd.start() val ssh = SshClient.setUpDefaultClient() ssh.start() val session = ssh.connect(testUsername, sshHost, sshPort).verify(5, TimeUnit.SECONDS).getSession session.addPasswordIdentity(testPassword) session.auth.verify(5, TimeUnit.SECONDS) val channel:ClientChannel = session.createChannel(Channel.CHANNEL_SHELL) val baos = new ByteArrayOutputStream val w = new OutputStreamWriter(baos) w.write("id") w.close() channel.setIn(new ByteArrayInputStream(baos.toByteArray)) val out: ByteArrayOutputStream = new ByteArrayOutputStream val err: ByteArrayOutputStream = new ByteArrayOutputStream channel.setOut(out) channel.setErr(err) channel.open channel.waitFor(java.util.Arrays.asList(ClientChannelEvent.CLOSED), 0) val result: String = out.toString.trim println("-->'"+result+"'") // should print 'id' if the current os has an available "/bin/cat" command assert(result == "id") sshd.stop() } } Main.go -
dacr revised this gist
Jun 7, 2019 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // summary : SSH server and client operations both within a single script using apache sshd. // keywords : ssh, client, server, apache-sshd // publish : gist, snippet // authors : david -
dacr created this gist
Jun 7, 2019 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,79 @@ // summary : ssh server and client operations both within a single script. // keywords : ssh, client, server, apache-sshd // publish : gist, snippet // authors : david // id : a267b427-a378-445c-b91e-e26ddf889c72 import $ivy.`org.apache.sshd:sshd-core:2.0.0` import $ivy.`org.apache.sshd:sshd-sftp:2.0.0` import $ivy.`org.apache.sshd:sshd-scp:2.0.0` import java.util.concurrent.TimeUnit import org.apache.sshd.client.SshClient import org.apache.sshd.common.channel.Channel import org.apache.sshd.server.SshServer import org.apache.sshd.server.auth.password.PasswordAuthenticator import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider import org.apache.sshd.server.session.ServerSession import java.io.OutputStreamWriter import org.apache.sshd.client.channel.{ClientChannel, ClientChannelEvent} import java.io.ByteArrayInputStream import java.io.ByteArrayOutputStream import org.apache.sshd.server.shell.ProcessShellFactory // Everything in a object as soon as we have to deal with futures, promises, asynchronous operations // object Main { val sshHost = "localhost" val sshPort = 2222 val testUsername = "test" val testPassword = "test" def go:Unit = { println("Starting operations") val sshd = SshServer.setUpDefaultServer sshd.setHost(sshHost) sshd.setPort(sshPort) sshd.setShellFactory(new ProcessShellFactory("/bin/cat")) sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()) sshd.setPasswordAuthenticator(new PasswordAuthenticator { override def authenticate(username: String, password: String, serverSession: ServerSession): Boolean = { username==testUsername && password == testPassword } }) sshd.start() val ssh = SshClient.setUpDefaultClient() ssh.start() val session = ssh.connect(testUsername, sshHost, sshPort).verify(5, TimeUnit.SECONDS).getSession session.addPasswordIdentity(testPassword) session.auth.verify(5, TimeUnit.SECONDS) val channel:ClientChannel = session.createChannel(Channel.CHANNEL_SHELL) val baos = new ByteArrayOutputStream val w = new OutputStreamWriter(baos) w.write("id") w.close() channel.setIn(new ByteArrayInputStream(baos.toByteArray)) val out: ByteArrayOutputStream = new ByteArrayOutputStream val err: ByteArrayOutputStream = new ByteArrayOutputStream channel.setOut(out) channel.setErr(err) channel.open channel.waitFor(java.util.Arrays.asList(ClientChannelEvent.CLOSED), 0) val result: String = out.toString.trim println("-->'"+result+"'") // should print 'id' if the current os has an available "/bin/cat" command assert(result == "id") sshd.stop() } } Main.go