簡體   English   中英

使用chilkat python將zip文件上傳到SFTP服務器

[英]Upload zip files to a SFTP server using chilkat python

我正在使用以下腳本在SFTP服務器上上傳zip文件。 雖然我在服務器上看到了文件,但是它始終顯示為0 Kb

#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)

您沒有檢查呼叫的成功返回值。 如果openFile和CloseHandle均成功,但是UploadFile失敗,則結果將是服務器上的0長度文件。

您傳遞的文件名沒有UploadFile的路徑。 這意味着您試圖從應用程序的當前工作目錄上載文件“ file.zip”,無論該文件是什么。 我懷疑“ file.zip”實際上不在您的應用程序的當前工作目錄中。 您可以指定完整的絕對路徑或相對路徑,而不是“ file.zip”。 例如,“ c:\\ someDir \\ file.zip”。

另外,如果在檢查方法調用的成功/失敗之后發現失敗,請檢查對象的LastErrorText屬性(sftp.LastErrorText)的內容。 它將提供有關方法調用中發生的內容的詳細信息。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM