'Autodetect the file system on the remote device. Used by SCP operations.'

def _autodetect_fs(self, cmd=u'dir', pattern=u'Directory    of    (.*)/'):

    output = self.send_command_expect(cmd)
    match = re.search(pattern, output)
    if match:
        file_system = match.group(1)
        cmd = u'dir    {}'.format(file_system)
        output = self.send_command_expect(cmd)
        if (u'%    Invalid' not in output):
            return file_system
    raise ValueError(u'An    error    occurred    in    dynamically    determining    remote    file    system:    {}    {}'.format(cmd, output))
