我已经写了代码,将登录到远程服务器并执行以下2个命令cd /path to folder/
rm -rf /myfolder/view1class ssh:
client = None
def __init__(self, address, username, password):
print("Connecting to server.")
self.client = client.SSHClient()
self.client.set_missing_host_key_policy(client.AutoAddPolicy())
self.client.connect(address, username=username, password=password, look_for_keys=False)
def sendCommand(self, command):
if(self.client):
stdin, stdout, stderr = self.client.exec_command(command)
while not stdout.channel.exit_status_ready():
# Print data when available
if stdout.channel.recv_ready():
alldata = stdout.channel.recv(1024)
prevdata = b"1"
while prevdata:
prevdata = stdout.channel.recv(1024)
alldata += prevdata
print(str(alldata, "utf8"))
else:
print("Connection not opened.")connection = ssh(ipaddress, username, password)
connection.sendCommand("cd /path to folder/")
connection.sendCommand("rm -rf /myfolder/view1")
执行此操作后不会删除文件夹。请帮忙