如何使用Python将共享网络文件设为只读?

时间:2009-10-13 16:46:07

标签: python

使用Python,当文件位于网络共享(从Windows 2003 Server提供)时,将文件设置为只读的正确方法是什么?

我在OS X(10.6.1)中运行Python 2.6.2。

以下代码在路径为本地时抛出异常(如预期),但当路径指向Windows共享时,os.chmod似乎无效。

import os, stat

path = '/Volumes/Temp/test.txt'

# Create a test file.
open(path, 'w').close()

# Make the file read-only.
os.chmod(path, stat.S_IREAD)

# Try writing to it again. This should fail.
open(path, 'w').close()

1 个答案:

答案 0 :(得分:0)

我很确定您必须在本地SAMBA服务器(/etc/samba/smb.conf)上进行适当的设置才能使其按照您的方式运行。如果未正确设置smb.conf,有很多方法可以绕过权限检查。

相关问题