Do you need to send several subsequent commands or just one? You can send
more than one command in a string separated by a semicolon (or one of ||,
&& depending on what you are trying to do and your shell). I do not
recommend it for normal use. You lose out on things like the exit codes
from all but the last command in the string.
A quick search reveals a lot of examples out there (not necessarily related
to Go) suggesting that one should combine the commands like "cd somedir;
cmd1; cmd2".
Also, this may work.
session.Run("cd somedir && some_extra_cmd arg1 arg2")
You could keep a format string that gets used each time.
cmdFmt := "cd somedir && %s"
session.Run(fmt.Sprintf(cmdFmt, "some_extra_cmd arg1 arg2"))
Or write a wrapper function.
func runSession(sess *ssh.Session, cmd string) error {
return sess.Run(fmt.Sprintf("cd somedir && %s", cmd))
}
Although, to answer your question, I do not see a way to set the directory
for a connection. I would imagine that each session is meant to be unique
in that regard. Or maybe more so, the sshd running on the remote host
would have to support such a feature for a whole connection.
On Sat, Jun 29, 2013 at 4:42 AM, Iwan Budi Kusnanto wrote:Hi
How to change working directory of ssh.ClientConn?
I have tried sesssion.Run("cd somedir") but it not worked.
From my understanding, we send each command by create new session then
call Start or Run.
If we change directory by calling session.Run or session.Start it will
only affect that session, not ClientConn.
And it is useless because a session can only send one command.
Any suggestion?
--
Iwan Budi Kusnanto
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out. --
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscribe@googlegroups.com.
For more options, visit
https://groups.google.com/groups/opt_out.