0

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

sftp = chilkat.CkSFtp() chilkat sftp 30日間試用版を使用してシステムにログインできると思います。

現在、ルート ディレクトリ (リモート マシン内) にいて、2 つのフォルダーがあります。これら 2 つのフォルダーのいずれかを変更し、そこに txt ファイルを作成したいと考えています。

どうすれば進めますか

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.")

このスクリプトは正常に実行され、「成功」と出力されます

4

1 に答える 1

0

SFTP プロトコルには、「現在の作業ディレクトリ」という概念がありません (FTP とは逆です)。

一部の SFTP クライアント (クライアント ライブラリ) では、「現在の作業ディレクトリ」をローカルでエミュレートできますが、Chilkat ではそうではないようです。

したがって、ファイルを作成するときは、絶対パスを使用する必要があります。/folder1/file.txt

ファイルを作成するには、OpenFileメソッドを使用します。その内容を書き込むには、いずれかのWriteFile*方法を使用します。

于 2015-01-05T09:32:38.163 に答える