【发布时间】:2017-02-26 13:14:15
【问题描述】:
所以我正在尝试使用 pexpect 将我的所有 torrent 文件发送到带有 scp 的服务器。这在大多数情况下都有效,但并不是我所有的 torrent 文件都会被发送。即使 'if i==0' 中的打印功能会打印出所有种子。如果我去服务器并删除发送的所有内容并再次运行它,则会发送相同的 torrent 文件。有谁知道可能是什么问题?
import os
import getpass
import subprocess
import pexpect
filepath = 'my downloads dir'
os.chdir(filepath)
var_password = str(getpass.getpass())
destination = "user@server:dir"
for filename in os.listdir():
if filename.endswith('.torrent'):
try:
var_command = "scp " + filepath + filename + " " + destination
var_child = pexpect.spawn(var_command)
i = var_child.expect(["password:", pexpect.EOF])
if i==0: # send password
print('Sending: ' + filename)
var_child.sendline(var_password)
var_child.expect(pexpect.EOF)
elif i==1:
print("Got the key or connection timeout")
pass
except Exception as e:
print("Oops Something went wrong buddy")
print(e)
【问题讨论】:
-
为什么不创建
*.torrent文件的存档,然后使用scp发送呢?另外,脚本中的 scp 命令在哪里?var_command? -
什么是var_command?此外,您可能正在超时连接,或者可能正在为服务器发送包含不兼容字符/空格的文件。
-
在这里,抱歉我在重构代码时删除了它。但我正试图让它发挥作用,因为它将成为更大系统的一部分
-
无论如何我都会压缩文件,将其发送到目标服务器,然后在那里解压。
标签: python operating-system scp pexpect torrent