简体   繁体   中英

PHP ssh2_scp_send file permissions

I am using the PHP function ssh2_scp_send to transfer files from one server to another. The interesting things is that if I write the permission in it's octal form (ie 0644) directly everything works fine. If I instead enclose this in inverted commas or use a variabel this does not work any more.

To be clearer: This works: ssh2_scp_send($conn, $localFile, $remoteFile, 0644);

Does NOT work: ssh2_scp_send($conn, $localFile, $remoteFile, "0644");

Does NOT work: $permission=0644;ssh2_scp_send($conn, $localFile, $remoteFile, $permission);

Anybody has any idea why this is the case?

Give decoct() a chance. I'm not sure this will work, but you can try. One more thing you can try is to store permissions values into constants with define()

The string may be interpreted as decimal.

Also, what type is $permission ? Try using var_dump() on it. It may be a string too.

$a = 0644;

$b = (int) "0644";

var_dump($a, $b); // int(420), int(644)

See it on codepad.org

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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