그래서 모든 토런트 파일을 pexpect를 사용하여 scp가있는 서버로 보내려고합니다. 이것은 대부분의 경우 작동하지만 내 토렌트 파일이 모두 전송되는 것은 아닙니다. 'if i == 0'의 print 함수가 모든 급류를 출력하지만. 그리고 서버로 가서 전송 된 모든 것을 삭제하고 다시 실행하면 동일한 토런트 파일이 전송됩니다. 문제가 무엇인지 아는 사람 있습니까?Python이 pexpect를 사용하여 scp를 통해 파일을 전송하는 중
import os
import getpass
import subprocess
import pexpect
filepath = 'my downloads dir'
os.chdir(filepath)
var_password = str(getpass.getpass())
destination = "[email protected]: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'? – JazZ
var_command 란 무엇입니까? 또한 연결 시간이 초과되었거나 서버에 호환되지 않는 문자/공백이있는 파일을 보낼 수 있습니다. – David
여기에 코드를 리팩토링 할 때 삭제하니 죄송합니다. 하지만 큰 시스템의 한 부분이 될 것이므로이 작업을 수행하려고합니다. – hjaltist