def size(self, path, request): '''Executes the FTP SIZE command on the given path.''' self.conn.voidcmd('TYPE I') # SIZE is not usually allowed in ASCII mode size = self.conn.size(path) if not str(size).isdigit(): self.conn.close() return None data = BytesIO(bytes(size)) # To ensure the BytesIO gets cleaned up, we need to alias its close # method to the release_conn() method. This is a dirty hack, but there # you go. data.release_conn = data.close data.content_len = size response = build_text_response(request, data, '213') self.conn.close() return response
def size(self, path, request): '''Executes the FTP SIZE command on the given path.''' self.conn.voidcmd( 'TYPE I') # SIZE is not usually allowed in ASCII mode size = self.conn.size(path) if not str(size).isdigit(): self.conn.close() return None data = BytesIO(bytes(size)) # To ensure the BytesIO gets cleaned up, we need to alias its close # method to the release_conn() method. This is a dirty hack, but there # you go. data.release_conn = data.close data.content_len = size response = build_text_response(request, data, '213') self.conn.close() return response