def list_files(self) : self.conn = RemoteClient._connect(self) directory_name = data["LIST_FILES_DIRECTORY_NAME"] cmd = "ls -lrth " + directory_name stdin, stdout, stderr = self.conn.exec_command(cmd) response = stdout.readlines() for line in response : logger.info(f'{line}')
def execute_command(self) : self.conn = RemoteClient._connect(self) for cmd in self.commands : if cmd == "display_file" : self.cat_file() elif cmd == "create_directory" : self.create_directory() elif cmd == "list_files" : self.list_files()
def create_directory(self) : self.conn = RemoteClient._connect(self) directory_name = data["REMOTE_DIR_NAME"] cmd = 'mkdir ' + directory_name stdin, stdout, stderr = self.conn.exec_command(cmd) if stdout.channel.recv_exit_status() == 0 : logger.info("Directory created") else : logger.error("Directory already exists")
def cat_file(self) : self.conn = RemoteClient._connect(self) file_name = data["REMOTE_FILE_NAME"] cmd = 'cat ' + file_name stdin, stdout, stderr = self.conn.exec_command(cmd) if stdout.channel.recv_exit_status() == 0 : response = stdout.readlines() for line in response : logger.info(f'{line}') else : logger.error("File does not exist")