Paramiko SFTPAttributes 中的属性
Attributes in Paramiko SFTPAttributes
http://docs.paramiko.org/en/stable/api/sftp.html#paramiko.sftp_attr.SFTPAttributes 显示 SFTP 属性的文档,现在
我在终端中执行了以下代码
>>> import paramiko
>>> from stat import S_ISDIR
>>>
>>> client = paramiko.SSHClient()
>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> client.connect('ipaddress', username='xxx', password='xxx', banner_timeout=60)
>>> sftp = client.open_sftp()
>>> dl= '/home/generic/'
>>> a=sftp.listdir_attr(dl)
>>> print(a)
[<SFTPAttributes: [ size=4096 uid=1000 gid=1000 mode=040775 atime=1624152009 mtime=1622179445 ]>, <SFTPAttributes: [ size=4096 uid=1000 gid=1000 mode=040775 atime=1624172765 mtime=1623920761 ]>, <SFTPAttributes: [ size=1100 uid=1000 gid=1000 mode=0100600 atime=1624121097 mtime=1624121097 ]>]
我得到了文档中解释的 SFTP 属性。
但是,我怀疑当我检查上面返回的每个项目时,比如 dir(a[0])
它有以下项目:
>>> dir(a[0])
['FLAG_AMTIME', 'FLAG_EXTENDED', 'FLAG_PERMISSIONS', 'FLAG_SIZE', 'FLAG_UIDGID', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_debug_str', '_flags', '_from_msg', '_pack', '_rwx', '_unpack', 'asbytes', 'attr', 'filename', 'from_stat', 'longname', 'st_atime', 'st_gid', 'st_mode', 'st_mtime', 'st_size', 'st_uid']
>>> type(a[0])
<class 'paramiko.sftp_attr.SFTPAttributes'>
>>>
上面传递的文档没有给出有关 filename
、longname
、asbytes
等的提示。
这些属性是从哪里添加的?我如何从文档本身理解它?
你的问题有点含糊,只能引用SFTPAttributes
documentation:
Representation of the attributes of a file (or proxied file) for SFTP in client or server mode. It attemps to mirror the object returned by os.stat as closely as possible, so it may have the following fields, with the same meanings as those returned by an os.stat object:
st_size
st_uid
st_gid
st_mode
st_atime
st_mtime
Because SFTP allows flags to have other arbitrary named attributes, these are stored in a dict named attr
. Occasionally, the filename is also stored, in filename
.
文档中唯一未提及的属性是 longname
,它通常包含类似于 *nix ls
命令输出的字符串。
其余一些,如 asbytes
和 from_stat
,是低级方法,而不是属性。除非你有特殊需求,否则你可以忽略这些。
http://docs.paramiko.org/en/stable/api/sftp.html#paramiko.sftp_attr.SFTPAttributes 显示 SFTP 属性的文档,现在
我在终端中执行了以下代码
>>> import paramiko
>>> from stat import S_ISDIR
>>>
>>> client = paramiko.SSHClient()
>>> client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
>>> client.connect('ipaddress', username='xxx', password='xxx', banner_timeout=60)
>>> sftp = client.open_sftp()
>>> dl= '/home/generic/'
>>> a=sftp.listdir_attr(dl)
>>> print(a)
[<SFTPAttributes: [ size=4096 uid=1000 gid=1000 mode=040775 atime=1624152009 mtime=1622179445 ]>, <SFTPAttributes: [ size=4096 uid=1000 gid=1000 mode=040775 atime=1624172765 mtime=1623920761 ]>, <SFTPAttributes: [ size=1100 uid=1000 gid=1000 mode=0100600 atime=1624121097 mtime=1624121097 ]>]
我得到了文档中解释的 SFTP 属性。
但是,我怀疑当我检查上面返回的每个项目时,比如 dir(a[0])
它有以下项目:
>>> dir(a[0])
['FLAG_AMTIME', 'FLAG_EXTENDED', 'FLAG_PERMISSIONS', 'FLAG_SIZE', 'FLAG_UIDGID', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_debug_str', '_flags', '_from_msg', '_pack', '_rwx', '_unpack', 'asbytes', 'attr', 'filename', 'from_stat', 'longname', 'st_atime', 'st_gid', 'st_mode', 'st_mtime', 'st_size', 'st_uid']
>>> type(a[0])
<class 'paramiko.sftp_attr.SFTPAttributes'>
>>>
上面传递的文档没有给出有关 filename
、longname
、asbytes
等的提示。
这些属性是从哪里添加的?我如何从文档本身理解它?
你的问题有点含糊,只能引用SFTPAttributes
documentation:
Representation of the attributes of a file (or proxied file) for SFTP in client or server mode. It attemps to mirror the object returned by os.stat as closely as possible, so it may have the following fields, with the same meanings as those returned by an os.stat object:
st_size
st_uid
st_gid
st_mode
st_atime
st_mtime
Because SFTP allows flags to have other arbitrary named attributes, these are stored in a dict named
attr
. Occasionally, the filename is also stored, infilename
.
文档中唯一未提及的属性是 longname
,它通常包含类似于 *nix ls
命令输出的字符串。
其余一些,如 asbytes
和 from_stat
,是低级方法,而不是属性。除非你有特殊需求,否则你可以忽略这些。