Skip to content

Instantly share code, notes, and snippets.

@michaelrice
Created May 11, 2014 07:27
Show Gist options
  • Save michaelrice/26cd4c2fedd68b1a6a73 to your computer and use it in GitHub Desktop.
Save michaelrice/26cd4c2fedd68b1a6a73 to your computer and use it in GitHub Desktop.
example of SCPClient
String runCommandWithOutput(Connection connection) {
log.trace("SCP command to place ${file} on ${host} at ${remotedir}")
output = new StringBuilder()
try {
SCPClient scp = connection.createSCPClient()
scp.put(file, 0, remotedir, "0600")
connection.close()
output.append("File $file should now be copied to $host:$remotedir\n")
}
catch (Exception e) {
log.error("Unable to copy ${file} to ${host}:${remotedir}", e)
output.append(e.message)
}
return output.toString()
}
@michaelrice
Copy link
Author

This is what I get in my logs:

2014-05-11 02:13:37,143 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection  - SSH port set in config: 22
2014-05-11 02:13:37,144 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection  - Opening connection to 10.12.254.10.
2014-05-11 02:13:37,318 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection  - User requested authType. Attempting to auth using keyboard-interactive
2014-05-11 02:13:37,318 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Created new InteractiveLogic: 
2014-05-11 02:13:37,534 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - attempting to reply to challenge.
2014-05-11 02:13:37,534 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Name: 
2014-05-11 02:13:37,534 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Instruction: 
2014-05-11 02:13:37,534 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Number of Promots: 1
2014-05-11 02:13:37,534 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Prompt: [Password:]
2014-05-11 02:13:37,535 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Echo: [false]
2014-05-11 02:13:37,535 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Prompt: Password:
2014-05-11 02:13:37,535 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - The server is asking us for a password.
2014-05-11 02:13:37,535 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Content: [, , , Password:] Echo:  true
2014-05-11 02:13:37,540 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - attempting to reply to challenge.
2014-05-11 02:13:37,540 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Name: 
2014-05-11 02:13:37,540 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Instruction: 
2014-05-11 02:13:37,540 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Number of Promots: 0
2014-05-11 02:13:37,540 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Prompt: []
2014-05-11 02:13:37,540 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection$InteractiveLogic  - Echo: []
2014-05-11 02:13:37,544 [http-bio-8080-exec-9] TRACE remotessh.RemoteConnection  - Successfully created auth session using keyboard-interactive.
2014-05-11 02:13:37,585 [http-bio-8080-exec-9] TRACE remotessh.RemoteSCP  - SCP command to place C:\Users\errr\Desktop\rvi-jeeves.conf on 10.12.254.10 at /tmp

I then end up with a blank file on my server

~ # ls -l /tmp/
-rw-------    1 root     root                  0 May 11 06:45 C:\Users\errr\Desktop\rvi-jeeves.conf

If you wanted to see the RemoteConnection file that is also being used to get the Connection it can be found here: https://github.com/michaelrice/RemoteSSH/blob/devwork/src/groovy/grails/plugin/remotessh/RemoteConnection.groovy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment