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,)
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']), ))
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', ]), )
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
def jsonrpc_file_info(self, remote_path): return api.file_info(remote_path)
def file_exists_v1(self, request): return api.file_info(remote_path=_request_arg(request, 'remote_path', mandatory=True))