Python SFTP脚本的调试选项,例如ftp_setdebug(1)来记录消息

问题描述 投票:0回答:2

我正在bash上,并使用PYSFTP内部调用SFTP的python脚本。以前,当我使用FTP时,有一个ftp_setdebug(1)选项,以便我可以检查传输和再见消息。但是对于SFTP,我找不到任何这样的选项。我找到了sftp -vv,但是到底有多需要使用它呢?还有其他类似FTP的方法吗?我不想在脚本中包含任何打印语句。

bash sftp python-2.6 pysftp
2个回答
1
投票

API of pysftp提到您可以将log=True添加到Connection以登录到临时文件。您甚至可以登录到您选择的文件。

虽然没有指定如果您指定一个数字,即log=1,它将转储到标准输出!

示例:

>>> import pysftp
>>> conn = pysftp.Connection('localhost', 'username', password='password123', log=1)
DEB [20150320-03:25:19.575] thr=1   paramiko.transport: starting thread (client mode): 0xe071400
INF [20150320-03:25:19.579] thr=1   paramiko.transport: Connected (version 2.0, client OpenSSH_6.4p1)
DEB [20150320-03:25:19.580] thr=1   paramiko.transport: kex algos:['ecdh-sha2-nistp256', 'ecdh-sha2-nistp384', 'ecdh-sha2-nistp521', 'diffie-hellman-group-exchange-sha256', 'diffie-hellman-group-exchange-sha1', 'diffie-hellman-group14-sha1', 'diffie-hellman-group1-sha1'] server key:['ssh-rsa', 'ssh-dss', 'ecdsa-sha2-nistp256'] client encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', '[email protected]', '[email protected]', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', '[email protected]', '[email protected]', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', '[email protected]'] client mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-md5', 'hmac-sha1', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', '[email protected]', 'hmac-md5', 'hmac-sha1', '[email protected]', '[email protected]', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', '[email protected]', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', '[email protected]'] server compress:['none', '[email protected]'] client lang:[''] server lang:[''] kex follows?False
DEB [20150320-03:25:19.580] thr=1   paramiko.transport: Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEB [20150320-03:25:19.580] thr=1   paramiko.transport: using kex diffie-hellman-group14-sha1; server key type ssh-rsa; cipher: local aes128-ctr, remote aes128-ctr; mac: local hmac-sha1, remote hmac-sha1; compression: local none, remote none
DEB [20150320-03:25:19.623] thr=1   paramiko.transport: Switch to new keys ...
DEB [20150320-03:25:19.624] thr=2   paramiko.transport: Attempting password auth...
DEB [20150320-03:25:19.663] thr=1   paramiko.transport: userauth is OK
INF [20150320-03:25:19.676] thr=1   paramiko.transport: Authentication (password) successful!
>>> conn.chdir('/tmp')
DEB [20150320-03:25:25.672] thr=2   paramiko.transport: [chan 0] Max packet in: 32768 bytes
DEB [20150320-03:25:25.672] thr=1   paramiko.transport: [chan 0] Max packet out: 32768 bytes
DEB [20150320-03:25:25.672] thr=1   paramiko.transport: Secsh channel 0 opened.
DEB [20150320-03:25:25.673] thr=1   paramiko.transport: [chan 0] Sesch channel 0 request ok
INF [20150320-03:25:25.676] thr=2   paramiko.transport.sftp: [chan 0] Opened sftp connection (server version 3)
DEB [20150320-03:25:25.676] thr=2   paramiko.transport.sftp: [chan 0] stat(b'/tmp')
DEB [20150320-03:25:25.677] thr=2   paramiko.transport.sftp: [chan 0] normalize(b'/tmp')
>>> conn.close()
INF [20150320-03:25:28.723] thr=2   paramiko.transport.sftp: [chan 0] sftp session closed.
DEB [20150320-03:25:28.723] thr=2   paramiko.transport: [chan 0] EOF sent (0)
DEB [20150320-03:25:28.724] thr=1   paramiko.transport: EOF in transport thread
>>>

当然,如果您非交互地运行它,则具有相同的作用。


0
投票

我被log=1弄糊涂,以便澄清:

使用日志属性并声明路径:

import pysftp
conn = pysftp.Connection('localhost', 'usrname', password='pass', log="C:/Users/Fabian/Desktop/logfile.log")
© www.soinside.com 2019 - 2024. All rights reserved.