@@ -57,7 +57,7 @@ class ssh_channel(sock):
5757 #: Command specified for the constructor
5858 process = None
5959
60- def __init__ (self , parent , process = None , tty = False , wd = None , env = None , raw = True , * args , ** kwargs ):
60+ def __init__ (self , parent , process = None , tty = False , cwd = None , env = None , raw = True , * args , ** kwargs ):
6161 super (ssh_channel , self ).__init__ (* args , ** kwargs )
6262
6363 # keep the parent from being garbage collected in some cases
@@ -68,9 +68,9 @@ def __init__(self, parent, process = None, tty = False, wd = None, env = None, r
6868 self .tty = tty
6969 self .env = env
7070 self .process = process
71- self .cwd = wd or '.'
72- if isinstance (wd , six .text_type ):
73- wd = packing ._need_bytes (wd , 2 , 0x80 )
71+ self .cwd = cwd or '.'
72+ if isinstance (cwd , six .text_type ):
73+ cwd = packing ._need_bytes (cwd , 2 , 0x80 )
7474
7575 env = env or {}
7676 msg = 'Opening new channel: %r' % (process or 'shell' )
@@ -80,8 +80,8 @@ def __init__(self, parent, process = None, tty = False, wd = None, env = None, r
8080 if isinstance (process , six .text_type ):
8181 process = packing ._need_bytes (process , 2 , 0x80 )
8282
83- if process and wd :
84- process = b'cd ' + sh_string (wd ) + b' >/dev/null 2>&1; ' + process
83+ if process and cwd :
84+ process = b'cd ' + sh_string (cwd ) + b' >/dev/null 2>&1; ' + process
8585
8686 if process and env :
8787 for name , value in env .items ():
@@ -841,8 +841,11 @@ def process(self, argv=None, executable=None, tty=True, cwd=None, env=None, time
841841 >>> sh = s.process(executable='/bin/sh')
842842 >>> str(sh.pid).encode() in s.pidof('sh') # doctest: +SKIP
843843 True
844- >>> s.process(['pwd'], cwd='/tmp').recvall()
844+ >>> io = s.process(['pwd'], cwd='/tmp')
845+ >>> io.recvall()
845846 b'/tmp\n'
847+ >>> io.cwd
848+ '/tmp'
846849 >>> p = s.process(['python','-c','import os; os.write(1, os.read(2, 1024))'], stderr=0)
847850 >>> p.send(b'hello')
848851 >>> p.recv()
@@ -1068,7 +1071,7 @@ def is_exe(path):
10681071
10691072 script = 'echo PWNTOOLS; for py in python3 python2.7 python2 python; do test -x "$(which $py 2>&1)" && echo $py && exec $py -c %s check; done; echo 2' % sh_string (script )
10701073 with context .quiet :
1071- python = ssh_process (self , script , tty = True , raw = True , level = self .level , timeout = timeout )
1074+ python = ssh_process (self , script , tty = True , cwd = cwd , raw = True , level = self .level , timeout = timeout )
10721075
10731076 try :
10741077 python .recvline_contains (b'PWNTOOLS' ) # Magic flag so that any sh/bash initialization errors are swallowed
@@ -1151,14 +1154,19 @@ def system(self, process, tty = True, wd = None, env = None, timeout = None, raw
11511154
11521155 Examples:
11531156 >>> s = ssh(host='example.pwnme')
1154- >>> py = s.run ('python3 -i')
1157+ >>> py = s.system ('python3 -i')
11551158 >>> _ = py.recvuntil(b'>>> ')
11561159 >>> py.sendline(b'print(2+2)')
11571160 >>> py.sendline(b'exit()')
11581161 >>> print(repr(py.recvline()))
11591162 b'4\n'
11601163 >>> s.system('env | grep -a AAAA', env={'AAAA': b'\x90'}).recvall()
11611164 b'AAAA=\x90\n'
1165+ >>> io = s.system('pwd', wd='/tmp')
1166+ >>> io.recvall()
1167+ b'/tmp\n'
1168+ >>> io.cwd
1169+ '/tmp'
11621170 """
11631171
11641172 if wd is None :
@@ -1844,6 +1852,13 @@ def set_working_directory(self, wd = None, symlink = False):
18441852 >>> _=s.set_working_directory(symlink=symlink)
18451853 >>> assert b'foo' in s.ls().split(), s.ls().split()
18461854 >>> assert homedir != s.pwd()
1855+
1856+ >>> _=s.set_working_directory()
1857+ >>> io = s.system('pwd')
1858+ >>> io.recvallS().strip() == io.cwd
1859+ True
1860+ >>> io.cwd == s.cwd
1861+ True
18471862 """
18481863 status = 0
18491864
0 commit comments