2011-11-29 3 views
12

Paramiko의 SFTPClient를 사용하여 호스트간에 파일을 전송하고 있습니다. 스크립트에서 scp를 사용하여 볼 수있는 출력과 비슷한 파일 전송 진행 상황을 인쇄하기를 원합니다.paramiko를 사용하여 (로그) 파일 전송 진행 상태를 확인하는 방법은 무엇입니까?

$ scp my_file [email protected] 

[email protected] password: 

my_file       100% 816KB 815.8KB/s 00:00 

$ 

어떤 아이디어가 있습니까? 사전에

덕분에

답변

16

put function의 선택적 콜백 매개 변수를 사용합니다. 이 같은 것은 :

def printTotals(transferred, toBeTransferred): 
    print "Transferred: {0}\tOut of: {1}".format(transferred, toBeTransferred) 

sftp.put("myfile","myRemoteFile",callback=printTotals) 
+0

완벽합니다. 덕분에 – user1071501

+0

"Out of"은 "Still to send"보다 나은 용어 일 수 있습니다. 왜냐하면 마지막 금액이 바뀌지 않기 때문입니다. – Dss

+0

@dss 그 경우입니까? 2 년이 지났습니다. 'toBeTransferred'숫자가 총계인지 아니면 나머지인지 기억하지 못합니다. –

관련 문제