Setting permissions on remote directory using Net::SFTP

T

timothy.hill

Hi,

I am in the process of writing a script that puts files on a remote
unix box from a windows machine (I am also using Net::SSH::W32Perl). It
is important that these files are placed in the correct directory and
if that directory does not exist, it must be created with the correct
permissions (777). For this I am using the do_mkdir() function. I am
able to create the directory fine, but I just cannot get the
permissions to set correctly - I have put loads of different numbers
into this, but have been able to get anything but rwxrwxrwx on the
directory. The code I have hacked for this bit is:

my $attrs = new Net::SFTP::Attributes();
$attrs->flags(15);
$attrs->size(4096);
$attrs->uid($ftp_info{$user}->{'uid'});
$attrs->gid($ftp_info{$user}->{'gid'});
$attrs->perm(16895);
$attrs->atime(time);
$attrs->mtime(time);

$sftp->do_mkdir($remote_dir, $attrs);

The 16895 value you see is the mode value I have obtained from doing a
stat on a directory that has the required permissions, but running this
code only produces drwxr-xr-x premissions. This is driving me potty -
can anyone help?

Cheers

Tim
 
J

John W. Krahn

I am in the process of writing a script that puts files on a remote
unix box from a windows machine (I am also using Net::SSH::W32Perl). It
is important that these files are placed in the correct directory and
if that directory does not exist, it must be created with the correct
permissions (777). For this I am using the do_mkdir() function. I am
able to create the directory fine, but I just cannot get the
permissions to set correctly - I have put loads of different numbers
into this, but have been able to get anything but rwxrwxrwx on the
directory. The code I have hacked for this bit is:

my $attrs = new Net::SFTP::Attributes();
$attrs->flags(15);
$attrs->size(4096);
$attrs->uid($ftp_info{$user}->{'uid'});
$attrs->gid($ftp_info{$user}->{'gid'});
$attrs->perm(16895);
$attrs->atime(time);
$attrs->mtime(time);

$sftp->do_mkdir($remote_dir, $attrs);

The 16895 value you see is the mode value I have obtained from doing a
stat on a directory that has the required permissions, but running this
code only produces drwxr-xr-x premissions. This is driving me potty -
can anyone help?

16895 is too large, you can't set the fifteenth bit. Try it with:

$attrs->perm( 0777 ); # octal notation

Or:

$attrs->perm( 511 ); # decimal notation

Or:

$attrs->perm( 0x1ff ); # hexadecimal notation




John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,698
Latest member
LydiaHalle

Latest Threads

Top