我想创建一个文件名(登录配置.xml)以远程(Linux)机器的特定目录中的某些内容为例,在桌面目录cd~/desktop/下。你知道吗
我正在使用import telnetlib模块来访问cd~/Desktop/甚至我也可以创建一个文件,但不幸的是在中插入了下面的内容(登录配置.xml文件)
下面是我的代码:
import telnetlib
tn = telnetlib.Telnet(HOST)
tn.read_until(b"login: ")
tn.write(user.encode('ascii') + b"\n")
if password:
tn.read_until(b"Password: ")
tn.write(password.encode('ascii') + b"\n")
file_create1=tn.write(b"touch /opt/loginConfig.xml"+ b"\n")
#go to opt directory
next_line_come = tn.read_until(b"#")
tn.write(b"chmod 777 /opt/loginConfig.xml"+ b"\n")
next_line_come = tn.read_until(b"#")
location=tn.write(b"/opt/loginConfig.xml")
write_under_file=open(b"location","w+")
write_under_file.write('<config\n')
write_under_file.write('user="name"\n')
write_under_file.write('password="admin!"\n')
write_under_file.write('autoLogin="true"\n'
文件正在创建不能在文件下写入内容的文件写入内容的好方法是什么?你知道吗
执行
open(b"location","w+")
操作时,您只是打开一个名为“location”的本地文件,而不是在远程系统上创建的文件。如果要使用telnet写入远程文件,必须发出与在终端提示符中使用的命令相同的命令:echo "Some line" >> /remote/path/to/somefile
。你知道吗现在,在本地机器上准备文件,然后使用文件传输协议(FTP或else)移动到另一台主机通常要容易得多。你知道吗
相关问题 更多 >
编程相关推荐