0

I am using the following script to upload a zip file on a SFTP server. Though I see the file on server, but it always shows that it's 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)

1 Answers1

0

You're not checking the success return values for the calls. If openFile and CloseHandle both succeeded, but UploadFile failed, then the result would be a 0-length file on the server.

You passed a filename with no path to UploadFile. This means you're trying to upload the file "file.zip" from the current working directory of your application, whatever that is. I suspect that "file.zip" is not actually located in your app's current working directory. You can specify a full absolute path, or relative path instead of "file.zip". For example, "c:\someDir\file.zip".

Also, if after checking the success/failure of a method call you find that it failed, examine the contents of the object's LastErrorText property (sftp.LastErrorText). It will provide details about what transpired in the method call.

Chilkat Software
  • 1,405
  • 1
  • 9
  • 8
  • Also.. the filename passed to OpenFile is the filename to be created on the server. The filepath passed to UploadFile is the local file path. – Chilkat Software Oct 17 '17 at 23:55