在Python错误中通过ssh.client发送带有sftp的文件

时间:2015-07-27 20:00:32

标签: python django ssh sftp

我正在尝试使用Paramiko和SFTP通过SSH发送文件。上传成功完成,但文件似乎不完整。可能是什么原因?

path = 'data.json'
ssh = paramiko.SSHClient()
ssh.load_host_keys(os.path.expanduser(os.path.join("~", ".ssh", "known_hosts")))
ssh.connect(host, username=user, password=pass)
sftp = ssh.open_sftp()
sftp.put(path,path)
sftp.close()
ssh.close()

DEB [20150727-21:37:41.332] thr=1   paramiko.transport: starting thread (client mode): 0xa212ad0L
INF [20150727-21:37:41.355] thr=1   paramiko.transport: Connected (version 2.0, client OpenSSH_6.2)
DEB [20150727-21:37:41.360] thr=1   paramiko.transport: kex algos:[u'some_group'] server key:[u'ssh-rsa', u'ssh-dss'] client encrypt:[u'some_username'] server encrypt:[u'some_username'] client mac:[u'some_user'] server mac:[u'some_mac'] client compress:[u'none'] server compress:[u'none'] client lang:[u''] server lang:[u''] kex follows?False
DEB [20150727-21:37:41.360] thr=1   paramiko.transport: Ciphers agreed: local=aes128-ctr, remote=aes128-ctr
DEB [20150727-21:37:41.360] 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 [20150727-21:37:41.401] thr=1   paramiko.transport: Switch to new keys ...
DEB [20150727-21:37:41.409] thr=1   paramiko.transport: userauth is OK
DEB [20150727-21:37:41.421] thr=1   paramiko.transport: Authentication type (password) not permitted.
DEB [20150727-21:37:41.421] thr=1   paramiko.transport: Allowed methods: [u'publickey', u'keyboard-interactive']
DEB [20150727-21:37:41.426] thr=1   paramiko.transport: userauth is OK
INF [20150727-21:37:41.553] thr=1   paramiko.transport: Authentication (keyboard-interactive) successful!
DEB [20150727-21:37:41.562] thr=2   paramiko.transport: [chan 0] Max packet in: 32768 bytes
DEB [20150727-21:37:41.570] thr=1   paramiko.transport: [chan 0] Max packet out: 32768 bytes
DEB [20150727-21:37:41.570] thr=1   paramiko.transport: Secsh channel 0 opened.
DEB [20150727-21:37:41.571] thr=1   paramiko.transport: [chan 0] Sesch channel 0 request ok
INF [20150727-21:37:41.581] thr=2   paramiko.transport.sftp: [chan 0] Opened sftp connection (server version 3)
DEB [20150727-21:37:41.581] thr=2   paramiko.transport.sftp: [chan 0] open('/Users/arturataide/Desktop/data.json', 'wb')
DEB [20150727-21:37:41.582] thr=2   paramiko.transport.sftp: [chan 0] open('/Users/arturataide/Desktop/data.json', 'wb') -> 00000000
DEB [20150727-21:37:41.583] thr=2   paramiko.transport.sftp: [chan 0] close(00000000)
DEB [20150727-21:37:41.583] thr=2   paramiko.transport.sftp: [chan 0] stat('/Users/arturataide/Desktop/data.json')
DEB [20150727-21:37:41.584] thr=2   paramiko.transport.sftp: [chan 0] stat('/Users/arturataide/Desktop/data.json')
INF [20150727-21:37:41.584] thr=2   paramiko.transport.sftp: [chan 0] sftp session closed.
DEB [20150727-21:37:41.584] thr=2   paramiko.transport: [chan 0] EOF sent (0)
DEB [20150727-21:37:41.585] thr=1   paramiko.transport: EOF in transport thread

我在Django做这个。

我可以使用一些帮助。感谢

编辑:

我可以成功上传图片文件,但json文件仍然无法完整上传

1 个答案:

答案 0 :(得分:0)

如果没有看到回溯,我会认为此行中存在错误。

sftp.put(path,path )sftp.close()

请尝试以下方法:

sftp.put(path,path )
sftp.close()