def gotClient(self, client, request, filepath): self.client = client protocol = FTPFileListProtocol() return client.list(filepath, protocol).addCallbacks( callback=self._build_response, callbackArgs=(request, protocol), errback=self._failed, errbackArgs=(request, ))
def _get_files(self): try: file_list = FTPFileListProtocol() yield self.list('.', file_list) yield self._retrieve_files(file_list) except Exception as e: log.err('Exception while listing or retrieving files (%s)' % e) reactor.callLater(CHECK_INTERVAL, self._get_files)
def connectionMade(self, ftpClient): """ A callback function for a successful connection """ # Get a detailed listing of the current directory self.twisted_FTP_client = ftpClient fileList = FTPFileListProtocol() d = ftpClient.list(self.read_path, fileList) d.addCallbacks(self.__getFiles, self.fail, callbackArgs=(fileList, ftpClient))
def gotClient(self, client, request, filepath): if isinstance(request, FileFtpRequest): return super(FtpListingHandler, self).gotClient(client, request, filepath) protocol = FTPFileListProtocol() return client.list(filepath, protocol).addCallbacks( callback=self._build_response, callbackArgs=(request, protocol), errback=self._failed, errbackArgs=(request, ))
def gotClient(self, client, request, filepath): self.client = client if split(filepath)[1]: # is file protocol = ReceivedDataProtocol() return client.retrieveFile(filepath, protocol)\ .addCallbacks(callback=self._build_response, callbackArgs=(request, protocol), errback=self._failed, errbackArgs=(request,)) else: # is dir protocol = FTPFileListProtocol() return client.list(filepath[1:], protocol).addCallbacks( callback=self._build_response_dir, callbackArgs=(request, protocol), errback=self._failed, errbackArgs=(request,))
def gotClient(self, client, request, filepath): """ Gets files list or one file """ # Check what class sent a request if not isinstance(request, ListFtpRequest): return super(FtpListingHandler, self).gotClient(client, request, filepath) protocol = FTPFileListProtocol() return client.list(filepath, protocol).addCallbacks( callback=self._build_response, callbackArgs=(request, protocol), errback=self._failed, errbackArgs=(request, ))
def gotClient(self, client, request, filepath): # download file if isinstance(request, FTPListRequest): # ftp listings proto = FTPFileListProtocol() result = client.list(filepath, proto).addCallbacks( callback=self._build_listing_response, callbackArgs=[request, proto], errback=self._failed, errbackArgs=[request], ) client.quit() return result result = super().gotClient(client, request, filepath) client.quit() return result
def connectionMade(ftpClient): # Get the current working directory ftpClient.pwd().addCallbacks(success, fail) # Get a detailed listing of the current directory fileList = FTPFileListProtocol() d = ftpClient.list(".", fileList) d.addCallbacks(showFiles, fail, callbackArgs=(fileList, )) # Change to the parent directory ftpClient.cdup().addCallbacks(success, fail) # Create a buffer proto = BufferingProtocol() # Get short listing of current directory, and quit when done d = ftpClient.nlst(".", proto) d.addCallbacks(showBuffer, fail, callbackArgs=(proto, )) d.addCallback(lambda result: reactor.stop())
def ftpFetchList(self, *args, **kwargs): self.filelist = FTPFileListProtocol() d = self.ftpclient.list(self.path, self.filelist) d.addCallback(self.listRcvd).addErrback(self.connectionFailed)