> import paramiko > def exec_command(trans, command): > chan = trans.open_session() > chan.exec_command(command) > stdin = chan.makefile('wb') > stdout = chan.makefile('rb') > stderr = chan.makefile_stderr('rb') > return stdin, stdout, stderr > def main(): > client = paramiko.SSHClient() > client.connect(hostname, username=username, password=password) > trans = client.get_transport() > dummy_chan = trans.open_session() > exec_command(trans, 'cd temp') > stdin, stdout, stderr = exec_command(pwd) > >>From the last line I found from stdout that the pwd is not changed. I tried > to type the full path in 'cd', did not help. Other UNIX commands such as ls, > mkdir, cp, rm will work. Only this 'cd' never works. I got stuck here. > > Please help. Thanks!
It works. However, each exec_command opens a new session. Within the first session, you do the cd command, and in the second session, the process in whose context the cd was executed has already terminated. You get a new process, and that starts out with the default directory again. You need to open a remote shell, and send commands to its command line; AFAICT, you can't use exec_command for that. Regards, Martin -- http://mail.python.org/mailman/listinfo/python-list