你知道是否真的有办法从 sftp 服务器获取“ctime”(文件创建的时间戳)吗?使用 paramiko 进行 sftp,我只看到“atime”和“mtime”。但是,我正在尝试访问文件的原始创建时间戳(而不是“atime”)。
这是我构建的当前代码,但注释掉了有关文件创建时间戳的部分,因为它会导致错误:
for file in tqdm(sftp.listdir()): # Debug check: print('We are now in the try loop:') # Look for files that have the same starting 25 characters as the column # in the mapper file: mask = mapper.file_name_startswith.str[:25].str.contains(file[:25]) # Grab the destination path info from the mapper file: dest_path = mapper[mask]['destination_path'].values[0] # Get the timestamp of the original file before we remove it, for both modified & created: remote_mod_time = sftp.stat(file).st_mtime # Need to use a different method to get the created date: ''' remote_file_attrs = sftp.listdir_attr('.') for attr in remote_file_attrs: if attr.filename == file: remote_create_time = attr.st_ctime break ''' # Move the current file to our desired local (destination) path: local_path = os.path.join(dest_path, file) sftp.get(file, local_path) # Set the modified date timestamp of the downloaded file to match the timestamp of the original file: os.utime(local_path, (remote_mod_time, remote_mod_time)) # Set the created date (cannot use os.utime for this) to match the timestamp of the original file: #date_time = pywintypes.Time(remote_create_time) #win32file.SetFileTime(local_path, date_time, None, None) # Remove the current file, which is being processed, from the sftp server: #sftp.remove(file) # Append the file to the "done_file" list: done_files.append(file)
正确答案
仅从 SFTP 版本 4 开始支持文件创建时间。大多数 SFTP 服务器(尤其是 OpenSSH)仅支持 SFTP 版本 3。 Paramiko 也是如此(在客户端)。
因此在大多数情况下(即使您修补 Paramiko 以支持 SFTP 4),您将无法从 SFTP 服务器检索创建时间。
如果您具有服务器的 shell 访问权限,您也许能够使用 shell 命令检索创建时间。但这不再是 SFTP 问题。
以上是使用 Paramiko SFTP 获取文件的创建时间戳的详细内容。更多信息请关注PHP中文网其他相关文章!

Python列表切片的基本语法是list[start:stop:step]。1.start是包含的第一个元素索引,2.stop是排除的第一个元素索引,3.step决定元素之间的步长。切片不仅用于提取数据,还可以修改和反转列表。

ListSoutPerformarRaysin:1)DynamicsizicsizingandFrequentInsertions/删除,2)储存的二聚体和3)MemoryFeliceFiceForceforseforsparsedata,butmayhaveslightperformancecostsinclentoperations。

toConvertapythonarraytoalist,usEthelist()constructororageneratorexpression.1)intimpthearraymoduleandcreateanArray.2)USELIST(ARR)或[XFORXINARR] to ConconverTittoalist,请考虑performorefformanceandmemoryfformanceandmemoryfformienceforlargedAtasetset。

choosearraysoverlistsinpythonforbetterperformanceandmemoryfliceSpecificScenarios.1)largenumericaldatasets:arraysreducememoryusage.2)绩效 - 临界杂货:arraysoffersoffersOffersOffersOffersPoostSfoostSforsssfortasssfortaskslikeappensearch orearch.3)testessenforcety:arraysenforce:arraysenforc

在Python中,可以使用for循环、enumerate和列表推导式遍历列表;在Java中,可以使用传统for循环和增强for循环遍历数组。1.Python列表遍历方法包括:for循环、enumerate和列表推导式。2.Java数组遍历方法包括:传统for循环和增强for循环。

本文讨论了Python版本3.10中介绍的新“匹配”语句,该语句与其他语言相同。它增强了代码的可读性,并为传统的if-elif-el提供了性能优势

Python中的功能注释将元数据添加到函数中,以进行类型检查,文档和IDE支持。它们增强了代码的可读性,维护,并且在API开发,数据科学和图书馆创建中至关重要。


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

记事本++7.3.1
好用且免费的代码编辑器

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

SecLists
SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

适用于 Eclipse 的 SAP NetWeaver 服务器适配器
将Eclipse与SAP NetWeaver应用服务器集成。