makedirs() 后其他应用程序的权限被拒绝 [英] Permission Denied to Other App after makedirs()

查看:54
本文介绍了makedirs() 后其他应用程序的权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在创建文件夹的服务器上运行 Python 应用程序时

When I have a Python app running on a server which is creating folders like this

    if not os.path.exists(destinationPath):
        os.makedirs(destinationPath, 777)

我有一个客户端应用程序(也在 Python 中)使用 Paramiko 模块通过 SFTP 将文件上传到服务器一>.如果需要,客户端也会像这样在服务器上创建文件夹

I have a client app (also in Python) uploading files to the server via SFTP using the Paramiko module. The client also creates folders on the server if needed like this

    makeCommand = 'mkdir -p "' + remotePath + '"'
        ssh.exec_command(makeCommand)

这很好用.我遇到的问题是,如果服务器应用程序创建一个文件夹,则客户端无权访问该文件夹(无法上传到该文件夹​​或创建子文件夹).我收到以下错误

and this works fine. The problem I'm having is that if the server app makes a folder, the client doesn't have access to that folder (can't upload to it or create subfolders). I get the following error

   line 104, in upload
ftMan.sftp.put(localFile, remoteFile)
File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 565, in put
File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 245, in open
File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 635, in _request
File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 682, in _read_response
File "build/bdist.macosx-10.8-intel/egg/paramiko/sftp_client.py", line 710, in _convert_status
IOError: [Errno 13] Permission denied

我怎样才能让每个应用程序创建另一个也可以使用的文件夹?我已尝试设置权限(如您在上面服务器的第一段代码中所见),但这似乎不起作用?

How can I have each app create folders that the other can use also? I've tried setting permissions (as you can see in the first piece of code for the server above) but this doesn't seem to be working?

推荐答案

我发现了一个类似的问题 here 事实证明 os.makedirs() 中的 mode 参数在某些系统上被忽略.您需要使用 os.chmod 来解决这个问题.对于创建的文件夹,我现在正在做

I found a similar question question here and it turns out the mode argument in os.makedirs() is ignored on some systems. You need to use os.chmod to get around this. For folders created I'm now doing

    for dirpath, dirnames, filenames in os.walk(theDirectory):
        os.chmod(dirpath, 0777)

偶尔更改已创建文件夹中的所有权限.这已经解决了问题,客户端应用程序可以与服务器应用程序创建的文件夹进行交互.

occasionally to change all permissions in created folders. This has solved to problem and the client app can interact with folders created by the server app.

这篇关于makedirs() 后其他应用程序的权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆