pysftp unable to list file details

410 views
Skip to first unread message

Andrea Buzzi

unread,
Apr 13, 2014, 9:44:15 AM4/13/14
to pys...@googlegroups.com
Hello,

I'm trying to use pysftp to get full directory listing including creation date.
If I try the execute "ls -al" on a ubuntu machine, everything works just fine:

*** Working scenario ***
>>> import pysftp
>>> srv = pysftp.Connection(host='10.58.xxx.xxx', username="xxxx", password="xxxx")
>>> srv.execute('ls -al')
['total 532\n', 'drwxr-xr-x 17 ***** *****   4096 Apr  9 10:13 .\n', 'drwxr-xr-x  3 root  root    4096 Dec  4 17:06 ..\n', '-rw-r--r--  1 ***** *****    838 Mar 20  2013 1\n', '-rw-rw-r--  1 ***** *****   6318 Dec 13 14:49 a\n', '-rw-r--r--  1 root  root    3067 Jun 20  2013 aa\n', '-rw-rw-r--  1 ***** *****   1805 Mar  6  2013 b\n', '-rw-------  1 ***** *****   2329 Apr 11 14:51 .bash_history\n', '-rw-r--r--  1 ***** *****    220 Dec  4 17:06 .[...]
rwx------  1 ***** *****   1695 Mar 20  2013 test_vpn\n', 'drwxr-xr-x  2 ***** *****   4096 Jul 15  2011 Videos\n', '-rw-------  1 ***** *****   5226 Apr  8 19:49 .viminfo\n', '-rw-r--r--  1 ***** *****   8918 Jul  3  2012 vlan\n', '-rw-r--r--  1 ***** *****   3029 Mar 20  2013 vpn_list\n', '-rw-r--r--  1 ***** *****    554 Mar 20  2013 vpn_list_orig\n']
>>> srv.close()

On a different system I'm unable to perform full listing:

*** Not working scenario ***
>>>
>>> import pysftp
>>> srv = pysftp.Connection(host='10.58.xxx.yyy', username="xxxx", password="xxxx")
>>> srv.listdir()
[u'.auto', u'pcmcia1', u'flash', u'records', u'hd-raid']
>>> srv.listdir('flash')
[u'crashlog2', u'boot.sys', u'persistdump', u'crsh2', u'tao', u'module.sys', u'.chassisid', u'patch', u'Vimpelcom.cfg', u'sai', u'VF_Quantum.cfg', u'production.51852.asr5000.bin', u'VF_Quantum_real4G.cfg', u'vf', u'configs', u'starent.key', u'starent.pem.cer', u'ubiqsys_cert.txt.txt', u'radius-sim.tar.gz', u'production.41940.asr5000.bin', u'production.44677.asr5000.bin', u'production.44756.asr5000.bin', u'production.49465.asr5000.bin']
>>> srv.execute('ls -al')
[]
>>>

The sftp server do accept the "ls -al" commands. This can be proved by following command sequence:

abuzzi-mac:python abuzzi$ sftp ad...@10.58.xxx.yyy
ad...@10.58.xxx.yyy's password:
Connected to 10.58.xxx.yyy.
sftp> dir /flash
/flash/VF_Quantum.cfg                   /flash/VF_Quantum_real4G.cfg            /flash/Vimpelcom.cfg                    /flash/boot.sys                        
/flash/configs                          /flash/crashlog2                        /flash/crsh2                            /flash/module.sys                      
/flash/patch                            /flash/persistdump                      /flash/production.41940.asr5000.bin     /flash/production.44677.asr5000.bin    
/flash/production.44756.asr5000.bin     /flash/production.49465.asr5000.bin     /flash/production.51852.asr5000.bin     /flash/radius-sim.tar.gz               
/flash/sai                              /flash/starent.key                      /flash/starent.pem.cer                  /flash/tao                             
/flash/ubiqsys_cert.txt.txt             /flash/vf                              
sftp> ls -la /flash
drwxrwxr-x    9 0        0            8192 Jan  1  1970 .
drwxr-xr-x    3 0        0               0 Apr 13 15:34 ..
-rwxrwxr-x    1 0        0              13 Feb 23  2012 .chassisid
-rwxrwxr-x    1 0        0           25622 Nov 11 18:42 VF_Quantum.cfg
-rwxrwxr-x    1 0        0           20396 Mar 19 12:51 VF_Quantum_real4G.cfg
-rwxrwxr-x    1 0        0           22352 Sep 18  2013 Vimpelcom.cfg
-rwxrwxr-x    1 0        0             748 Dec 11 13:46 boot.sys
drwxrwxr-x    2 0        0            4096 Apr 30  2013 configs
-rwxrwxr-x    1 0        0         3920672 Mar 19 12:48 crashlog2
drwxrwxr-x    2 0        0            4096 Mar 19 12:48 crsh2
-rwxrwxr-x    1 0        0             157 Oct 30  2012 module.sys
drwxrwxr-x    2 0        0            4096 May  7  2013 patch
drwxrwxr-x    2 0        0            4096 Sep 24  2013 persistdump
-rwxrwxr-x    1 0        0         4382238 Jul 22  2011 radius-sim.tar.gz
drwxrwxr-x    2 0        0            4096 Apr  1  2011 sai
-rwxrwxr-x    1 0        0             887 May 11  2010 starent.key
-rwxrwxr-x    1 0        0            1360 May 11  2010 starent.pem.cer
drwxrwxr-x    2 0        0            4096 Apr 30  2013 tao
-rwxrwxr-x    1 0        0            1256 Apr 11  2011 ubiqsys_cert.txt.txt
drwxrwxr-x    2 0        0            4096 Apr  1  2011 vf
sftp> ls -la
drwxrwxr-x    4 0        0             140 Mar 14 15:57 .
drwxrwxr-x    4 0        0             140 Mar 14 15:57 ..
drwxrwxr-x    4 0        0              80 Mar 14 15:57 .auto
lrwxrwxrwx    1 0        0              19 Mar 14 15:57 flash
drwxr-xr-x    6 0        0              81 Oct  3  2013 hd-raid
lrwxrwxrwx    1 0        0              23 Mar 14 15:57 pcmcia1
lrwxrwxrwx    1 0        0              15 Mar 14 15:57 records
sftp>

Why pysftp seems unable to perform the full directory listing ?

Thx,
A.
Reply all
Reply to author
Forward
0 new messages