'Sets the working directory in which future commands will
be run (via ssh.run) and to which files will be uploaded/downloaded
from if no path is provided
Note:
This uses ``mktemp -d`` under the covers, sets permissions
on the directory to ``0700``.  This means that setuid binaries
will **not** be able to access files created in this directory.
In order to work around this, we also ``chmod +x`` the directory.
Arguments:
wd(string): Working directory.  Default is to auto-generate a directory
based on the result of running \'mktemp -d\' on the remote machine.
symlink(bool,str): Create symlinks in the new directory.
The default value, ``False``, implies that no symlinks should be
created.
A string value is treated as a path that should be symlinked.
It is passed directly to the shell on the remote end for expansion,
so wildcards work.
Any other value is treated as a boolean, where ``True`` indicates
that all files in the "old" working directory should be symlinked.
Examples:
>>> s =  ssh(host=\'example.pwnme\',
...         user=\'travis\',
...         password=\'demopass\')
>>> cwd = s.set_working_directory()
>>> s.ls()
>>> s.pwd() == cwd
True
>>> s =  ssh(host=\'example.pwnme\',
...         user=\'travis\',
...         password=\'demopass\')
>>> homedir = s.pwd()
>>> _=s.touch(\'foo\')
>>> _=s.set_working_directory()
>>> assert s.ls() == \'\'
>>> _=s.set_working_directory(homedir)
>>> assert \'foo\' in s.ls().split()
>>> _=s.set_working_directory(symlink=True)
>>> assert \'foo\' in s.ls().split()
>>> assert homedir != s.pwd()
>>> symlink=os.path.join(homedir,\'*\')
>>> _=s.set_working_directory(symlink=symlink)
>>> assert \'foo\' in s.ls().split()
>>> assert homedir != s.pwd()'

def set_working_directory(self, wd=None, symlink=False):

    status = 0
    if (symlink and (not isinstance(symlink, str))):
        symlink = os.path.join(self.pwd(), '*')
    if (not wd):
        (wd, status) = self.run_to_end('x=$(mktemp    -d)    &&    cd    $x    &&    chmod    +x    .    &&    echo    $PWD', wd='.')
        wd = wd.strip()
        if status:
            self.error(('Could    not    generate    a    temporary    directory    (%i)\n%s' % (status, wd)))
    else:
        cmd = ('ls    ' + sh_string(wd))
        (_, status) = self.run_to_end(cmd, wd='.')
        if status:
            self.error(('%r    does    not    appear    to    exist' % wd))
    self.info(('Working    directory:    %r' % wd))
    self.cwd = wd
    if symlink:
        self.ln('-s', symlink, '.')
    return self.cwd
