Thanks the ssh2-python project! It gives me a great help :)
My SSH server is Windows 10, the client is an Ubuntu Linux. There is no argument with ssh2.channel.execute() function to specific a working directory, so I'd like to call ssh2.channel.setenv() before using execute() function, but I encountered a ssh2.exceptions.ChannelRequestDenied exception !
I tried to trace the source code with the ChannelRequestDenied keyword, then I found it was raised in libssh2/src/channel.c!channel_setenv() function. Seems it handles with "env" for shell in Unix-like environment only, and Windows should do with set in cmd.exe. (my guess)
libssh2/src/channel.c!channel_setenv()
static int channel_setenv(LIBSSH2_CHANNEL *channel,
const char *varname, unsigned int varname_len,
const char *value, unsigned int value_len)
{
...
*(s++) = SSH_MSG_CHANNEL_REQUEST;
_libssh2_store_u32(&s, channel->remote.id);
_libssh2_store_str(&s, "env", sizeof("env") - 1);
*(s++) = 0x01;
_libssh2_store_str(&s, varname, varname_len);
_libssh2_store_str(&s, value, value_len);
...
return _libssh2_error(session, LIBSSH2_ERROR_CHANNEL_REQUEST_DENIED,
"Unable to complete request for channel-setenv");
}
Traceback (most recent call last):
File "/home/dougpuob/workspace/dougpuob/qemu-tasker/qemu-tasker.git/src/module/sshclient.py", line 166, in execute
ret_setenv = ssh_chanl.setenv("PATH", self.envvar_path)
File "ssh2/channel.pyx", line 298, in ssh2.channel.Channel.setenv
File "ssh2/utils.pyx", line 174, in ssh2.utils.handle_error_codes
ssh2.exceptions.ChannelRequestDenied
Expected behaviour: [What was expected to happen.]
The setenv() function work without exceptions, then the PATH environment variable will be changed to new one.
Actual behaviour: [What actually happened.]
I encountered a ssh2.exceptions.ChannelRequestDenied exception.
Additional info: [Include version of libssh2 and any other relevant information.]
I known I can combine my command with the cd command, but sometimes I got unexpected value with the get_exit_status() function.
Directions
Thanks the
ssh2-python
project! It gives me a great help :)My SSH server is Windows 10, the client is an Ubuntu Linux. There is no argument with ssh2.channel.execute() function to specific a working directory, so I'd like to call ssh2.channel.setenv() before using execute() function, but I encountered a
ssh2.exceptions.ChannelRequestDenied
exception !I tried to trace the source code with the
ChannelRequestDenied
keyword, then I found it was raised inlibssh2/src/channel.c!channel_setenv()
function. Seems it handles with"env"
for shell in Unix-like environment only, and Windows should do withset
in cmd.exe. (my guess)libssh2/src/channel.c!channel_setenv()
Bug reports
Code to reproduce
Traceback
Expected behaviour: [What was expected to happen.]
The
setenv()
function work without exceptions, then thePATH
environment variable will be changed to new one.Actual behaviour: [What actually happened.]
I encountered a
ssh2.exceptions.ChannelRequestDenied
exception.Additional info: [Include version of
libssh2
and any other relevant information.]I known I can combine my command with the
cd
command, but sometimes I got unexpected value with theget_exit_status()
function.