def mount(self):
        """Mounts the sftp system if it's not already mounted."""
        if self.mounted:
            return

        self._mount_point_local_create()

        if len(self.system.mount_opts) == 0:
            sshfs_opts = ""
        else:
            sshfs_opts = " -o %s" % " -o ".join(self.system.mount_opts)

        if self.system.auth_method == self.system.AUTH_METHOD_PUBLIC_KEY:
            ssh_opts = '-o PreferredAuthentications=publickey -i %s' % self.system.ssh_key
        elif self.system.auth_method:
            ssh_opts = '-o PreferredAuthentications=%s' % self.system.auth_method
        else:
            ssh_opts = '-o PreferredAuthentications=password'

        cmd = ("{cmd_before_mount} &&"
               " sshfs -o ssh_command="
               "'ssh -o ConnectTimeout={timeout} -p {port} {ssh_opts}'"
               " {sshfs_opts} {user}@{host}:{remote_path} {local_path}")
        cmd = cmd.format(
            cmd_before_mount = self.system.cmd_before_mount,
            timeout = self.SSH_CONNECT_TIMEOUT,
            port = self.system.port,
            ssh_opts = ssh_opts,
            sshfs_opts = sshfs_opts,
            host = self.system.host,
            user = self.system.user,
            remote_path = self.mount_point_remote,
            local_path = self.mount_point_local,
        )

        output = shell_exec(cmd).strip()

        if not self.mounted:
            # Clean up the directory tree
            self._mount_point_local_delete()
            if output == '':
                output = 'Mounting failed for a reason unknown to sftpman.'
            raise SftpMountException(cmd, output)
def mount ( self ) : if self . mounted : return self . _mount_point_local_create ( ) if len ( self . system . mount_opts ) == 0 : sshfs_opts = "" else : sshfs_opts = " -o %s" % " -o " . join ( self . system . mount_opts ) if self . system . auth_method == self . system . AUTH_METHOD_PUBLIC_KEY : ssh_opts = '-o PreferredAuthentications=publickey -i %s' % self . system . ssh_key elif self . system . auth_method : ssh_opts = '-o PreferredAuthentications=%s' % self . system . auth_method else : ssh_opts = '-o PreferredAuthentications=password' cmd = ( "{cmd_before_mount} &&" " sshfs -o ssh_command=" "'ssh -o ConnectTimeout={timeout} -p {port} {ssh_opts}'" " {sshfs_opts} {user}@{host}:{remote_path} {local_path}" ) cmd = cmd . format ( cmd_before_mount = self . system . cmd_before_mount , timeout = self . SSH_CONNECT_TIMEOUT , port = self . system . port , ssh_opts = ssh_opts , sshfs_opts = sshfs_opts , host = self . system . host , user = self . system . user , remote_path = self . mount_point_remote , local_path = self . mount_point_local , ) output = shell_exec ( cmd ) . strip ( ) if not self . mounted : self . _mount_point_local_delete ( ) if output == '' : output = 'Mounting failed for a reason unknown to sftpman.' raise SftpMountException ( cmd , output )
Mounts the sftp system if it's not already mounted.