Skip to content

Instantly share code, notes, and snippets.

@seandenigris
Last active December 13, 2015 17:08
Show Gist options
  • Save seandenigris/4945462 to your computer and use it in GitHub Desktop.
Save seandenigris/4945462 to your computer and use it in GitHub Desktop.
Pharo Smalltalk SSH/SFTP Client
"Set the following variables, some of which have reasonable defaults, for your environment"
The required expect file lives at https://gist.github.com/seandenigris/4945436"
command := 'sftp'. "Tested with ssh and sftp"
userName := 'root'.
ipAddress := ''.
password := ''.
prompt := 'sftp> '.
expectFilePath := '/path/to/expect_file.exp'.
escapedPassword := password copyReplaceAll: '"' with: '\"'.
p := PipeableOSProcess command: '/usr/bin/expect "', expectFilePath, '" ', escapedPassword, ' ', ipAddress, ' ', command.
"Must be non-blocking, or #upToEnd hangs the image"
p setNonBlockingOutput.
"Skip login response from the server"
[ | output |
output := p upToEnd.
lines := output lines.
lines size > 0 and: [ lines last beginsWith: prompt ] ] whileFalse.
p nextPutAll: 'pwd', Character cr asString.
p upToEnd.
"p errorUpToEnd."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment