简体   繁体   English

如何使用phpseclib更改sFTP服务器上文件的权限?

[英]How to change permissions for file on sFTP server using phpseclib?

I tried $sftp->chmod('0755', "file.zip"); 我试过$sftp->chmod('0755', "file.zip"); and $sftp->chmod('0755', "file.zip"); $sftp->chmod('0755', "file.zip");

But in both cases the permission has been set to 363 instead. 但是在两种情况下,权限都改为363。

At a guess the permissions are 1363. In other words octal(755). 猜测权限为1363。换句话说,八进制(755)。 It's a complete guess, but I would suggest that the chmod function is taking a decimal mode, rather than an octal one. 这是一个完整的猜测,但是我建议chmod函数采用的是十进制模式,而不是八进制模式。

0755 and '0755' are not the same thing as demonstrated thusly: 0755和'0755'与以下演示的内容不同:

<?php echo '0755' == 0755 ? 'equal' : 'not equal'; ?>;

Per that, try removing the single quotes around 0755. 因此,请尝试删除0755附近的单引号。

The reason phpseclib expects permissions to be represented as an octal value ('0755' is cast to a decimal value - not an octal one) is because that's how ftp_chmod does it and that's what Net_SFTP::chmod() is modeled after. phpseclib期望将权限表示为八进制值(“ 0755”强制转换为十进制值-而不是八进制值)的原因是因为ftp_chmod做到了这一点,并且正是Net_SFTP::chmod()的模型。 (actually, pretty much all of phpseclib's SFTP API is modeled after PHP's FTP extension API) (实际上,几乎所有phpseclib的SFTP API都是以PHP的FTP扩展API为模型的)

You can use 您可以使用

$sftp->chmod(0755, $file);

You should not input permissions into the phpseclib chmod() function as a string. 您不应将权限作为字符串输入phpseclib chmod()函数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM