示例#1
0
    def chown(self, uid, gid):
        """
        Change the owner (``uid``) and group (``gid``) of this file.  As with
        Python's `os.chown` function, you must pass both arguments, so if you
        only want to change one, use `stat` first to retrieve the current
        owner and group.

        :param int uid: new owner's uid
        :param int gid: new group id
        """
        self.sftp._log(DEBUG, 'chown(%s, %r, %r)' % (hexlify(self.handle), uid, gid))
        attr = SFTPAttributes()
        attr.st_uid, attr.st_gid = uid, gid
        self.sftp._request(CMD_FSETSTAT, self.handle, attr)
示例#2
0
    def chmod(self, path, mode):
        """
        Change the mode (permissions) of a file.  The permissions are
        unix-style and identical to those used by python's C{os.chmod}
        function.

        @param path: path of the file to change the permissions of.
        @type path: string
        @param mode: new permissions.
        @type mode: int
        """
        path = self._adjust_cwd(path)
        attr = SFTPAttributes()
        attr.st_mode = mode
        self._request(CMD_SETSTAT, path, attr)
示例#3
0
    def mkdir(self, path, mode=0777):
        """
        Create a folder (directory) named C{path} with numeric mode C{mode}.
        The default mode is 0777 (octal).  On some systems, mode is ignored.
        Where it is used, the current umask value is first masked out.

        @param path: name of the folder to create.
        @type path: string
        @param mode: permissions (posix-style) for the newly-created folder.
        @type mode: int
        """
        path = self._adjust_cwd(path)
        attr = SFTPAttributes()
        attr.st_mode = mode
        self._request(CMD_MKDIR, path, attr)
示例#4
0
    def stat(self):
        if self.content_provider.get(self.path) is None:
            return SFTP_NO_SUCH_FILE

        mtime = calendar.timegm(datetime.now().timetuple())

        sftp_attrs = SFTPAttributes()
        sftp_attrs.st_size = self.content_provider.get_size(self.path)
        sftp_attrs.st_uid = 0
        sftp_attrs.st_gid = 0
        sftp_attrs.st_mode = (stat.S_IRWXO | stat.S_IRWXG | stat.S_IRWXU |
                              (stat.S_IFDIR if self.content_provider.is_dir(
                                  self.path) else stat.S_IFREG))
        sftp_attrs.st_atime = mtime
        sftp_attrs.st_mtime = mtime
        sftp_attrs.filename = os.path.basename(self.path)
        return sftp_attrs
示例#5
0
    def chown(self, path, uid, gid):
        """
        Change the owner (C{uid}) and group (C{gid}) of a file.  As with
        python's C{os.chown} function, you must pass both arguments, so if you
        only want to change one, use L{stat} first to retrieve the current
        owner and group.

        @param path: path of the file to change the owner and group of.
        @type path: string
        @param uid: new owner's uid
        @type uid: int
        @param gid: new group id
        @type gid: int
        """
        path = self._adjust_cwd(path)
        attr = SFTPAttributes()
        attr.st_uid, attr.st_gid = uid, gid
        self._request(CMD_SETSTAT, path, attr)
示例#6
0
def put(sftp, localpath, remotepath, callback=None, confirm=True):

    file_size = os.stat(localpath).st_size
    fl = file(localpath, 'rb')
    try:
        size = 0
        fr = sftp.file(remotepath, 'ab')
        s = sftp.stat(remotepath)
        frSize = s.st_size
        print frSize, 'frSizefrSizefrSize'
        fr.set_pipelined(True)
        size = frSize
        print size, ' frSize'
        fl.seek(size)
        fr.seek(size)
        try:
            while True:
                data = fl.read(32768)
                if len(data) == 0:
                    break
                fr.write(data)
                size += len(data)
                if callback is not None:
                    callback(size, file_size)
        finally:
            print size, ' frfrsize'
            fr.seek(size)
            fr.close()
    finally:
        print size, '  flflsize'
        fl.seek(size)
        fl.close()
    if confirm:
        s = sftp.stat(remotepath)
        if s.st_size != size:
            return False
        elif file_size == s.st_size:
            return True
        else:
            return False
    else:
        s = SFTPAttributes()
    return s
示例#7
0
    def utime(self, path, times):
        """
        Set the access and modified times of the file specified by C{path}.  If
        C{times} is C{None}, then the file's access and modified times are set
        to the current time.  Otherwise, C{times} must be a 2-tuple of numbers,
        of the form C{(atime, mtime)}, which is used to set the access and
        modified times, respectively.  This bizarre API is mimicked from python
        for the sake of consistency -- I apologize.

        @param path: path of the file to modify.
        @type path: string
        @param times: C{None} or a tuple of (access time, modified time) in
            standard internet epoch time (seconds since 01 January 1970 GMT).
        @type times: tuple of int
        """
        path = self._adjust_cwd(path)
        if times is None:
            times = (time.time(), time.time())
        attr = SFTPAttributes()
        attr.st_atime, attr.st_mtime = times
        self._request(CMD_SETSTAT, path, attr)