像ftp_setdebug(1)记录消息的Python脚本SFTP调试选项 [英] Debug option for Python SFTP script like ftp_setdebug(1) to log messages

查看:669
本文介绍了像ftp_setdebug(1)记录消息的Python脚本SFTP调试选项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作bash和使用PYSFTP内部调用Python脚本为SFTP。 previously当我用FTP有一个ftp_setdebug(1)选项,这样我可以检查传输和再见消息。但对于SFTP,我无法找到任何这样的选择。我发现 SFTP -vv 但如何究竟一是需要使用它?有没有像FTP任何其他方法?我不想在脚本中包含任何打印语句。

I am working on bash and internally calling python Script for SFTP using PYSFTP. Previously when I used FTP there was a ftp_setdebug(1) option so that I can check the Transfer and goodbye messages. But for SFTP I am not able to find any such option. I found sftp -vv but how exactly does one need to use it? Is there any other method like FTP? I don't want to include any print statements in the script.

推荐答案

pysftp的API 提到,你可以添加一个日志= TRUE 连接登录到一个临时文件中。你甚至可以登录到您所选择的文件。

The API of pysftp mentions that you can add a log=True to the Connection to log to a temporary file. You could even log to a file of your choosing.

它没有提到的是,如果你指定一个数字,即登录= 1 ,将转储到stdout!

It doesn't mention though that if you specify a number, i.e. log=1, it will dump to stdout!

例如:

>>> 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', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] server encrypt:['aes128-ctr', 'aes192-ctr', 'aes256-ctr', 'arcfour256', 'arcfour128', 'aes128-gcm@openssh.com', 'aes256-gcm@openssh.com', 'aes128-cbc', '3des-cbc', 'blowfish-cbc', 'cast128-cbc', 'aes192-cbc', 'aes256-cbc', 'arcfour', 'rijndael-cbc@lysator.liu.se'] client mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] server mac:['hmac-md5-etm@openssh.com', 'hmac-sha1-etm@openssh.com', 'umac-64-etm@openssh.com', 'umac-128-etm@openssh.com', 'hmac-sha2-256-etm@openssh.com', 'hmac-sha2-512-etm@openssh.com', 'hmac-ripemd160-etm@openssh.com', 'hmac-sha1-96-etm@openssh.com', 'hmac-md5-96-etm@openssh.com', 'hmac-md5', 'hmac-sha1', 'umac-64@openssh.com', 'umac-128@openssh.com', 'hmac-sha2-256', 'hmac-sha2-512', 'hmac-ripemd160', 'hmac-ripemd160@openssh.com', 'hmac-sha1-96', 'hmac-md5-96'] client compress:['none', 'zlib@openssh.com'] server compress:['none', 'zlib@openssh.com'] 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
>>>

作品相同的,如果你运行它非交互的,当然。

Works the same if you run it non-interactively of course.

这篇关于像ftp_setdebug(1)记录消息的Python脚本SFTP调试选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆