FAQ
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.

Search Discussions

  • Jonathan Pittman at Jun 29, 2013 at 3:20 pm
    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.
  • Iwan Budi Kusnanto at Jul 1, 2013 at 7:27 am

    On Sat, Jun 29, 2013 at 10:20 PM, Jonathan Pittman wrote:
    }

    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.

    Hi Jonathan,

    Thanks for your long answer.
    I want to implement a kind of ssh client and i think sshd (from
    openssh) should already support this feature because we can 'cd' using
    ssh client shipped with Linux/BSD/Mac. Or maybe this ssh client do
    some trick to support this?

    And thanks for your multiple commands idea, i think it can become a
    workaround for this.

    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.


    --
    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.
  • Dave Cheney at Jul 1, 2013 at 8:33 am
    Changing directories on the remote host sounds like a symptom not the cause. Can I ask the problem you are trying to solve, ie why does your remote command need to be run in a particular directory? Is it not in the path?

    You mentioned openssh, I recommend you run your command using -vv and then compare the output to what you expect. If you can show what openssh is doing that the go client is not we can fix it. Also it would be useful to review the 'shell' session command from the ssh RFC.

    Cheers

    Dave
    On 01/07/2013, at 17:27, Iwan Budi Kusnanto wrote:

    On Sat, Jun 29, 2013 at 10:20 PM, Jonathan Pittman
    wrote:
    }
    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.

    Hi Jonathan,

    Thanks for your long answer.
    I want to implement a kind of ssh client and i think sshd (from
    openssh) should already support this feature because we can 'cd' using
    ssh client shipped with Linux/BSD/Mac. Or maybe this ssh client do
    some trick to support this?

    And thanks for your multiple commands idea, i think it can become a
    workaround for this.


    On Sat, Jun 29, 2013 at 4:42 AM, Iwan Budi Kusnanto <iwanbk@gmail.com>
    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.


    --
    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.
  • Shenshouer51 at Jul 10, 2015 at 10:49 am
    I Seen the problem!
    Because one ssh session can execute command once then will be close.
    and when one session was created, The current dir is the home of current
    user
    If you execute some command like "cd / && ls" , will list the dir /

    在 2013年6月29日星期六 UTC+8下午4:42:10,Iwan Budi Kusnanto写道:
    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/d/optout.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedJun 29, '13 at 8:42a
activeJul 10, '15 at 10:49a
posts5
users4
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase