0

http://www.example-code.com/python/sftp_writeTextFile.asp

I think I'm able to login in system using chilkat sftp sftp = chilkat.CkSFtp() 30 days trial version.

now I'm in root directory(in remote machine) and there are two folders. I want to change one of these two folders and create a txt file there.

How do I proceed

import sys
import chilkat

sftp = chilkat.CkSFtp()

success = sftp.UnlockComponent("Anything for 30-day trial")
if (success != True):
    print(sftp.lastErrorText())
    sys.exit()

#  Set some timeouts, in milliseconds:
sftp.put_ConnectTimeoutMs(15000)
sftp.put_IdleTimeoutMs(15000)

#  Connect to the SSH server.
#  The standard SSH port = 22
#  The hostname may be a hostname or IP address.

port = 22
success = sftp.Connect(hostname,port)
if (success != True):
    print(sftp.lastErrorText())
    sys.exit()

#  Authenticate with the SSH server.  Chilkat SFTP supports
#  both password-based authenication as well as public-key
#  authentication.  This example uses password authenication.
success = sftp.AuthenticatePw(username, password)
if (success != True):
    print(sftp.lastErrorText())
    sys.exit()

print("Success.")

this script successfully executing and printing "Success"

xyz
  • 197
  • 3
  • 16

1 Answers1

0

The SFTP protocol does not have a concept of "current working directory" (contrary to say FTP).

While some SFTP clients (client libraries) allow emulating the "current working directory" locally, it does not seem to be the case with Chilkat.

So you have to use absolute paths, when creating the file, e.g. /folder1/file.txt

To create the file, use the OpenFile method. To write its contents, use one of the WriteFile* methods.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992