Ejemplo n.º 1
0
    def _cbFileRecevied(self, consumer, local_path, newsegs):
        #         receive_defer.addCallback(self._startFileBackup, upload_filename, newsegs, d)
#         consumer.fObj.flush()
#         os.fsync(consumer.fObj.fileno())
#         consumer.fObj.close()
#         consumer.close()
        remote_path = '/'.join(newsegs)
        lg.out(8, 'ftp_server._cbFileRecevied %s %s' % (local_path, remote_path))
        ret = api.file_info(remote_path)
        if ret['status'] != 'OK':
            ret = api.file_create(remote_path)
            if ret['status'] != 'OK':
                return defer.fail(FileNotFoundError(remote_path))
        else:
            if ret['result']['type'] == 'dir':
                return defer.fail(IsADirectoryError(remote_path))
        ret = api.file_upload_start(local_path, remote_path, wait_result=False)
        if ret['status'] != 'OK':
            lg.warn('file_upload_start() returned: %s' % ret)
            return defer.fail(FileNotFoundError(remote_path))

#         shortPathID = backup_fs.ToID(full_path)
#         if not shortPathID:
#             shortPathID, _, _ = backup_fs.AddFile(full_path, read_stats=False)
#         item = backup_fs.GetByID(shortPathID)
#         item.read_stats(upload_filename)
#         backup_control.StartSingle(shortPathID, upload_filename)
#         # upload_task.result_defer.addCallback(self._cbFileBackup, result_defer, newsegs)
#         backup_fs.Calculate()
#         backup_control.Save()
        # result_defer.callback(None)
        # return consumer
        return (TXFR_COMPLETE_OK,)
Ejemplo n.º 2
0
 def ftp_SIZE(self, path):
     try:
         newsegs = toSegments(self.workingDirectory, path)
     except InvalidPath:
         return defer.fail(FileNotFoundError(path))
     full_path = '/'.join(newsegs)
     ret = api.file_info(full_path)
     if ret['status'] != 'OK':
         return defer.fail(FileNotFoundError(path))
     return succeed((FILE_STATUS, str(ret['size']), ))
Ejemplo n.º 3
0
 def file_info_v1(self, request):
     return api.file_info(
         remote_path=_request_arg(request, 'remote_path', mandatory=True),
         include_uploads=bool(
             _request_arg(request, 'include_uploads', '1') in [
                 '1',
                 'true',
             ]),
         include_downloads=bool(
             _request_arg(request, 'include_downloads', '1') in [
                 '1',
                 'true',
             ]),
     )
Ejemplo n.º 4
0
 def ftp_CWD(self, path):
     try:
         segments = toSegments(self.workingDirectory, path)
     except InvalidPath:
         # XXX Eh, what to fail with here?
         return defer.fail(FileNotFoundError(path))
     pth = '/'.join(segments)
     d = Deferred()
     d.addCallback(lambda r: self._accessGrantedResponse(r, segments))
     if not pth or pth == '/':
         d.callback(None)
         return d
     ret = api.file_info(pth, include_uploads=False, include_downloads=False)
     if ret['status'] != 'OK':
         d.errback(FileNotFoundError(path))
         return d
     if ret['result']['type'] == 'dir':
         d.callback(None)
     else:
         d.errback(FileNotFoundError(path))
     return d
Ejemplo n.º 5
0
 def jsonrpc_file_info(self, remote_path):
     return api.file_info(remote_path)
Ejemplo n.º 6
0
 def file_exists_v1(self, request):
     return api.file_info(remote_path=_request_arg(request, 'remote_path', mandatory=True))