2017-10-17 6 views
0

다음 스크립트를 사용하여 SFTP 서버에 zip 파일을 업로드하고 있습니다. 서버에서 파일을 볼 수는 있지만 항상 0 Kb임을 보여줍니다.chilkat python을 사용하여 SFTP 서버에 zip 파일 업로드

#Code to upload file to a SFTP server abc.com 
import chilkat 
sftp = chilkat.CkSFtp() 
success = sftp.UnlockComponent("Anything trial") 
puttyKey = chilkat.CkSshKey() 
ppkText = puttyKey.loadText("xyz.ppk") 
success = puttyKey.FromPuttyPrivateKey(ppkText) 
sshHostname = "abc.com" 
sshPort = 22 
success = sftp.Connect(sshHostname,sshPort) 
sftp.AuthenticatePwPk("username", "password", puttyKey) 
success = sftp.InitializeSftp() 
filename = "file.zip" 
handle = sftp.openFile(filename ,"writeOnly","createTruncate") 
success = sftp.UploadFile(handle,"file.zip") 
success = sftp.CloseHandle(handle) 

답변

0

호출에 대한 성공 반환 값을 확인하지 않습니다. openFile과 CloseHandle이 모두 성공했지만 UploadFile이 실패한 경우 결과는 서버에 길이가 0 인 파일이됩니다.

경로가없는 파일 이름을 UploadFile에 전달했습니다. 즉, 응용 프로그램의 현재 작업 디렉토리에서 "file.zip"파일을 업로드하려고합니다. 나는 "file.zip"이 실제로 앱의 현재 작업 디렉토리에 있지 않다고 생각합니다. 전체 절대 경로 또는 "file.zip"대신 상대 경로를 지정할 수 있습니다. 예 : "c : \ someDir \ file.zip"

또한 메서드 호출의 성공/실패를 확인한 후에 실패한 것으로 확인되면 개체의 LastErrorText 속성 (sftp.LastErrorText)의 내용을 검사하십시오. 메서드 호출에서 무엇이 발생했는지에 대한 세부 정보를 제공합니다.

+0

또한 OpenFile로 전달되는 파일 이름은 서버에 생성되는 파일 이름입니다. UploadFile에 전달 된 파일 경로는 로컬 파일 경로입니다. – Matt