通过telnet上传文件
我正在编写一个 python 脚本来将文件上传到我的文件服务器:
host = "myhost.dev"
tn = telnetlib.Telnet()
tn.open(host, 5202)
print tn.read_until("\n")
fp = "./output"
f = open(fp, "r")
f_body = f.read()
tn.write(f_body)
tn.write("\n")
f.close()
如果文件有一个换行符 - 0a
,并且它是 gzip 文件中二进制数据的一部分,我应该怎么做才能转义它? python telnetlib 可以自己完成吗?或者我应该这样做吗?
此致
Im writing a python scrpit to upload files to my file server:
host = "myhost.dev"
tn = telnetlib.Telnet()
tn.open(host, 5202)
print tn.read_until("\n")
fp = "./output"
f = open(fp, "r")
f_body = f.read()
tn.write(f_body)
tn.write("\n")
f.close()
If file has a new line character- 0a
, and it is part of a binary data in gzip file, what should I do to escape it ? Can python telnetlib do it by itself ? or should I do it ?
best regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为 telnet 不是传输文件的最佳选择,但如果您仍然想使用它来上传文件。您可以尝试执行以下操作(尚未尝试,但我认为应该可行)
I think that telnet is not the best option for transfering files, but if you still want to use it for uploading files. You may try to do the following (haven't tried, but I think should work)
也许 telnet 不是最好的解决方案,最好使用 FTP 或 HTTP。
telnet协议不适合传输文件,它的一些控制流程导致文件和特殊字符的传输困难。
如果你想使用非标准协议,最好使用套接字模块,使用套接字你就不会遇到 0a 的问题。
Maybe telnet is not the best solution for this, it is better to use FTP o HTTP.
The telnet protocol is not suitable for transmiting files, and it has some control flow processes that make if dificult to transmit files and special chars.
If you want to use a non standard protocol, it is better so use the socket module, with sockets you don't have this problems with 0a.