def action():
            path = self._getMappedPath(file_path)
            command = "RETR " + self.__encode(path)

            if self.config['debug_extras']['debug_remote_paths']:
                print ("FTPSync <debug> get path " + file_path + " => " + str(self.__encode(path)))

            def download(tempfile):

                def perBlock(data):
                    tempfile.write(data)

                    if blockCallback is not None:
                        blockCallback()

                try:
                    self.connection.retrbinary(command, perBlock)
                except Exception as e:
                    if self.__isErrorCode(e, ['ok', 'passive']):
                        self.connection.retrbinary(command, perBlock)
                    else:
                        raise

            existsLocally = os.path.exists(file_path)

            if self.config['use_tempfile']:
                viaTempfile(file_path, download, self.config['default_folder_permissions'])
            else:
                with open(file_path, 'wb') as destination:
                    download(destination)

            if existsLocally is False or self.config['always_sync_local_permissions']:
                try:
                    if self.config['default_local_permissions'] is not None and sys.platform != 'win32' and sys.platform != 'cygwin':
                        if self.config['default_local_permissions'] == "auto":
                            metadata = self.list(file_path)

                            if type(metadata) is list and len(metadata) > 0:
                                os.chmod(file_path, int(metadata[0].getPermissionsNumeric(),8))
                        else:
                            os.chmod(file_path, int(self.config['default_local_permissions'], 8))
                except Exception as e:
                    print ("FTPSync > Error setting local chmod [Exception: " + str(e) + "]")
        def action():
            path = self._getMappedPath(file_path)
            command = "RETR " + self.__encode(path)

            if self.config['debug_extras']['debug_remote_paths']:
                print ("FTPSync <debug> get path " + file_path + " => " + str(self.__encode(path)))

            isAscii = self._isAscii(file_path)
            isAscii = False
            action = 'retrbinary'
            mode = 'wb'
            if isAscii:
                action = 'retrlines'

            def download(tempfile):

                def perBlock(data):
                    if sys.version[0] == '2' or type(data) is bytes:
                        tempfile.write(data)
                    else:
                        tempfile.write(data.encode('utf-8'))

                    if isAscii:
                        # intentional, \n will be converted to os.linesep
                        if sys.version[0] == '2':
                            tempfile.write("\n")
                        else:
                            tempfile.write("\n".encode('utf-8'))

                    if blockCallback is not None:
                        blockCallback()

                try:
                    getattr(self.connection, action)(command, perBlock)
                except Exception as e:
                    if self.__isErrorCode(e, ['ok', 'passive']):
                        getattr(self.connection, action)(command, perBlock)
                    elif self.__isErrorCode(e, 'fileUnavailible'):
                        raise FileNotFoundException
                    else:
                        raise

            existsLocally = os.path.exists(file_path)

            if self.config['use_tempfile']:
                viaTempfile(file_path, download, self.config['default_folder_permissions'], mode)
            else:
                with open(file_path, mode) as destination:
                    download(destination)

            if existsLocally is False or self.config['always_sync_local_permissions']:
                try:
                    if self.config['default_local_permissions'] is not None and sys.platform != 'win32' and sys.platform != 'cygwin':
                        if self.config['default_local_permissions'] == "auto":
                            metadata = self.list(file_path)

                            if type(metadata) is list and len(metadata) > 0:
                                os.chmod(file_path, int(metadata[0].getPermissionsNumeric(),8))
                        else:
                            os.chmod(file_path, int(self.config['default_local_permissions'], 8))
                except Exception as e:
                    print ("FTPSync > Error setting local chmod [Exception: " + str(e) + "]")
示例#3
0
        def action():
            path = self._getMappedPath(file_path)
            command = "RETR " + self.__encode(path)

            if self.config['debug_extras']['debug_remote_paths']:
                print("FTPSync <debug> get path " + file_path + " => " +
                      str(self.__encode(path)))

            isAscii = self._isAscii(file_path)
            action = 'retrbinary'
            mode = 'wb'
            if isAscii:
                action = 'retrlines'

            def download(tempfile):
                def perBlock(data):
                    if sys.version[0] == '2':
                        tempfile.write(data)
                    else:
                        tempfile.write(data.encode('utf-8'))

                    if isAscii:
                        # intentional, \n will be converted to os.linesep
                        if sys.version[0] == '2':
                            tempfile.write("\n")
                        else:
                            tempfile.write("\n".encode('utf-8'))

                    if blockCallback is not None:
                        blockCallback()

                try:
                    getattr(self.connection, action)(command, perBlock)
                except Exception as e:
                    if self.__isErrorCode(e, ['ok', 'passive']):
                        getattr(self.connection, action)(command, perBlock)
                    elif self.__isErrorCode(e, 'fileUnavailible'):
                        raise FileNotFoundException
                    else:
                        raise

            existsLocally = os.path.exists(file_path)

            if self.config['use_tempfile']:
                viaTempfile(file_path, download,
                            self.config['default_folder_permissions'], mode)
            else:
                with open(file_path, mode) as destination:
                    download(destination)

            if existsLocally is False or self.config[
                    'always_sync_local_permissions']:
                try:
                    if self.config[
                            'default_local_permissions'] is not None and sys.platform != 'win32' and sys.platform != 'cygwin':
                        if self.config['default_local_permissions'] == "auto":
                            metadata = self.list(file_path)

                            if type(metadata) is list and len(metadata) > 0:
                                os.chmod(
                                    file_path,
                                    int(metadata[0].getPermissionsNumeric(),
                                        8))
                        else:
                            os.chmod(
                                file_path,
                                int(self.config['default_local_permissions'],
                                    8))
                except Exception as e:
                    print("FTPSync > Error setting local chmod [Exception: " +
                          str(e) + "]")