The overall goal: Copy the permissions of files from the local filesystem when uploading them over FTP using PHP.
The problem: While ftp_chmod appears to succeed, and according to the print statement in the code I'm setting the right permissions, it sets completely wrong permissions.
Kodu:
<?php
$perms = fileperms($src);
if ($perms !== false) {
// We only take the last 3 digits, since we're only interested in 'normal' file permissions, not extended ones.
$perms &= 511;
$permsm = sprintf('%o', $perms);
print "DEBUG: Setting permissions: $perms :: ". decoct($perms) ." :: $permsm :: $dst\n";
ftp_chmod($conn_id, $permsm, $dst);
}
?>
The result: Source / expected file permissions (local filesystem):
-rw-r--r-- 1 allen users 15572 Jun 2 12:40 Foo.docx -rw-r--r-- 1 allen users 16877 Jun 2 12:40 Bar.docx drwxr-xr-x 2 allen users 4096 Jun 15 14:01 configuration drwxr-xr-x 9 allen users 4096 Jun 15 14:01 content drwxr-xr-x 3 allen users 4096 Jun 15 14:01 local -rw-r--r-- 1 allen users 152274 Jun 11 17:13 foo1.sql -rw-r--r-- 1 allen users 9984 Mar 2 10:44 footest.sql drwxrwxrwx 2 allen users 4096 Jun 15 14:01 tmp drwxr-xr-x 3 allen users 4096 Jun 15 14:01 versions
Hedef / fiili sonuç dosya izinleri (ftp upload):
--w----r-T 1 ftptest ftptest 15572 Jun 15 14:42 Foo.docx --w----r-T 1 ftptest ftptest 16877 Jun 15 14:42 Bar.docx d-wxrw--wt 2 ftptest ftptest 4096 Jun 15 14:42 configuration d-wxrw--wt 9 ftptest ftptest 4096 Jun 15 14:42 content d-wxrw--wt 3 ftptest ftptest 4096 Jun 15 14:42 local --w----r-T 1 ftptest ftptest 152274 Jun 15 14:42 foo1.sql --w----r-T 1 ftptest ftptest 9984 Jun 15 14:42 footest.sql dr----x--t 2 ftptest ftptest 4096 Jun 15 14:42 tmp d-wxrw--wt 3 ftptest ftptest 4096 Jun 15 14:42 versions