Problems with Mirror - ftp.pl doesn't get the right octal for chmod 
Author Message
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Hi together,

I am using the perl-script mirror.pl (Lee McLoughlin) to mirror
files/dirs to a remote ftp server.
The file transfer works fine, but then it isn't able to change the
file mode value on the remote server (with chmod).

The following error occurs:
---> SITE CHMOD 100644 Testfile.txt
501 CHMOD: Mode value must be between 0 and 0777

octal 100644 and not octal 0644.

i examined the used script ftp.pl and found the following part:

        if( $mapunixout ){
                $path = eval "&$mapunixout( \$path, 'f' )";
        }

        &send( sprintf( "SITE CHMOD %o $path", $mode ) );
......

When I change the line to:

        &send( sprintf( "SITE CHMOD 0644 $path", $mode ) );

everything works fine, but It's sick to code such silly things :-)

Does anyone know, how to implement the function, that I got the right
mode (octal 0644) ?

Thx
Regards
Dirk Drexler



Tue, 11 May 2004 11:47:50 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod
Dirk wrote in comp.lang.perl.misc:

Quote:

> I am using the perl-script mirror.pl (Lee McLoughlin) to mirror
> files/dirs to a remote ftp server.
> The file transfer works fine, but then it isn't able to change the
> file mode value on the remote server (with chmod).

You should report the error to the author.

Quote:
> The following error occurs:
> ---> SITE CHMOD 100644 Testfile.txt
> 501 CHMOD: Mode value must be between 0 and 0777

> octal 100644 and not octal 0644.

> i examined the used script ftp.pl and found the following part:

>         if( $mapunixout ){
>                 $path = eval "&$mapunixout( \$path, 'f' )";
>         }

Looks like bad code; a subroutine reference would be better than an
eval.

Quote:
>         &send( sprintf( "SITE CHMOD %o $path", $mode ) );

This should work. $mode has probably a wrong value.

Quote:
> When I change the line to:

>         &send( sprintf( "SITE CHMOD 0644 $path", $mode ) );

> everything works fine, but It's sick to code such silly things :-)

Esp. if you're doing chmod on a directory.

Quote:
> Does anyone know, how to implement the function, that I got the right
> mode (octal 0644) ?

The author should know.

--
Rafael Garcia-Suarez / http://rgarciasuarez.free.fr/
Could Marconi have invented the radio if he hadn't by pure chance
spent years working at the problem? -- Monty Python, Penguins



Tue, 11 May 2004 11:59:35 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Quote:
> Hi together,

> I am using the perl-script mirror.pl (Lee McLoughlin) to mirror
> files/dirs to a remote ftp server.
> The file transfer works fine, but then it isn't able to change the
> file mode value on the remote server (with chmod).

> The following error occurs:
> ---> SITE CHMOD 100644 Testfile.txt
> 501 CHMOD: Mode value must be between 0 and 0777

> octal 100644 and not octal 0644.

> i examined the used script ftp.pl and found the following part:

>         if( $mapunixout ){
>                 $path = eval "&$mapunixout( \$path, 'f' )";
>         }

>         &send( sprintf( "SITE CHMOD %o $path", $mode ) );

This is bad code.  The author doesn't know how to use sprintf.  In
particular, variable strings ($path) do *not* belong in the sprintf
format.  The line should read

    &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

I left the ampersand in front of "&send" though that looks suspect
too.

No, I don't know how to fix it, but I'd distrust a script that contains
elementary errors like this one.

Anno



Tue, 11 May 2004 12:13:05 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Quote:

>The following error occurs:
>---> SITE CHMOD 100644 Testfile.txt
>501 CHMOD: Mode value must be between 0 and 0777

>octal 100644 and not octal 0644.

>        &send( sprintf( "SITE CHMOD %o $path", $mode ) );

>When I change the line to:

>        &send( sprintf( "SITE CHMOD 0644 $path", $mode ) );

>everything works fine, but It's sick to code such silly things :-)

OK... You need to remove the upper bits. Bitwise and is very nice for
that.

        &send( sprintf( "SITE CHMOD %o $path", 0777 & $mode ) );

--
        Bart.



Tue, 11 May 2004 13:31:32 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Quote:

>    &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

>I left the ampersand in front of "&send" though that looks suspect
>too.

"send" is a keyword in perl. If you have a sub called "send", then you
need to disambiguate the calls.

--
        Bart.



Tue, 11 May 2004 13:37:16 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Quote:

> >    &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

> >I left the ampersand in front of "&send" though that looks suspect
> >too.

> "send" is a keyword in perl. If you have a sub called "send", then you
> need to disambiguate the calls.

Oh, right.

Anno



Tue, 11 May 2004 13:47:45 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod
On 23 Nov 2001 11:13:05 GMT, Anno Siegel

[ snip ]

Quote:
>>         &send( sprintf( "SITE CHMOD %o $path", $mode ) );

> This is bad code.  The author doesn't know how to use sprintf.  In
> particular, variable strings ($path) do *not* belong in the sprintf
> format.  The line should read

>     &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

I suppose this is a matter of style.  The Perl manual page for
sprintf() and sprintf(3) certainly don't agree with you.  Assuming
that the interpolation results in no "conversion specification"
characters, the stuff in $path will be treated as "ordinary
characters", according to the manual pages.  

printf "%s\n", "just another Perl hacker";

--
Garry Williams



Tue, 11 May 2004 14:28:58 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Quote:

>> This is bad code.  The author doesn't know how to use sprintf.  In
>> particular, variable strings ($path) do *not* belong in the sprintf
>> format.  The line should read

>>     &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

>I suppose this is a matter of style.

No. I agree with Anno.

Quote:
>The Perl manual page for
>sprintf() and sprintf(3) certainly don't agree with you.  Assuming
>that the interpolation results in no "conversion specification"
>characters, the stuff in $path will be treated as "ordinary
>characters", according to the manual pages.  

>printf "%s\n", "just another Perl hacker";

What if the actual path name contains a "%"? That is far from unlikely,
you know.

Don't do it, especially as the change required for doing it right
(without this bug) is so dead easy.

--
        Bart.



Tue, 11 May 2004 15:09:36 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Quote:
> On 23 Nov 2001 11:13:05 GMT, Anno Siegel


> [ snip ]

> >>         &send( sprintf( "SITE CHMOD %o $path", $mode ) );

> > This is bad code.  The author doesn't know how to use sprintf.  In
> > particular, variable strings ($path) do *not* belong in the sprintf
> > format.  The line should read

> >     &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

> I suppose this is a matter of style.  The Perl manual page for
> sprintf() and sprintf(3) certainly don't agree with you.  Assuming
> that the interpolation results in no "conversion specification"
> characters, the stuff in $path will be treated as "ordinary
> characters", according to the manual pages.  

Oh, it certainly works in most cases.  The point is that you have to
make sure that no % (anything else?) appears in the interpolated
string.  For this, you either need a guarantee that it will never
be there in the first place (not true for path names in general), or
add code to detect that case (and then do what?).  Since you can
always replace an interpolation into the format string with a %s-
construct, string interpolation makes the code more fragile than it
has to be.  It is not merely a matter of style, IMHO.

This doesn't mean, of course, that string interpolation into the
format string is always wrong.  When used to build parts of formats,
as in "%${width}s", it is unexceptionable and powerful.

Anno



Tue, 11 May 2004 15:49:11 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

  >> &send( sprintf( "SITE CHMOD %o $path", $mode ) );

  AS> This is bad code.  The author doesn't know how to use sprintf.  In
  AS> particular, variable strings ($path) do *not* belong in the sprintf
  AS> format.  The line should read

  AS>     &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

why can't the sprintf format string interpolate? in fact that is the
only way to emulate c's s/printf using * for a field size and taking the
next argument for its value. and there are times when you want to
interpolate AND sprintf and interpolation is simpler and faster.
here is an example where i have some perl vars (one actually) and some
calls i want to merge into one string:

        my $info = sprintf( <<INFO,
SockMsg connected
Type:   $type
Local:  %s:%d
Remote: %s:%d
INFO
                                $connected_sock->sockhost(),
                                $connected_sock->sockport(),
                                $connected_sock->peerhost(),
                                $connected_sock->peerport(),
        ) ;

now if i used the Perl6::Interpolate (IIRC) module i could use $() in
the string and not need sprintf. of course perl6 will allow that.

i won't use the ugly and broken ${\} tricks.

uri

--

-- Stem is an Open Source Network Development Toolkit and Application Suite -
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org



Tue, 11 May 2004 23:28:00 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod
On 23 Nov 2001 14:49:11 GMT, Anno Siegel

Quote:


>> On 23 Nov 2001 11:13:05 GMT, Anno Siegel


>> [ snip ]

>> >>         &send( sprintf( "SITE CHMOD %o $path", $mode ) );

>> > This is bad code.  The author doesn't know how to use sprintf.  In
>> > particular, variable strings ($path) do *not* belong in the sprintf
>> > format.  The line should read

>> >     &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

>> I suppose this is a matter of style.  The Perl manual page for
>> sprintf() and sprintf(3) certainly don't agree with you.  Assuming
>> that the interpolation results in no "conversion specification"
>> characters, the stuff in $path will be treated as "ordinary
>> characters", according to the manual pages.  

> Oh, it certainly works in most cases.  The point is that you have to
> make sure that no % (anything else?) appears in the interpolated
> string.  

Okay, I agree it is not style here.  The case at hand should not be
coded the way it is for the reason you (and Bart) cite.  

--
Garry Williams



Wed, 12 May 2004 06:38:35 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod
Hello,

thanx for your efforts to solve my problem.
I tested

    &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

and got the same effect:
---> SITE CHMOD 100644 Testfile.txt
501 CHMOD: Mode value must be between 0 and 0777

Tests with Bart's:

        &send( sprintf( "SITE CHMOD %o $path", 0777 & $mode ) );

worked fine.
Regards from rainy Germany

Dirk Drexler

Quote:


> >The following error occurs:
> >---> SITE CHMOD 100644 Testfile.txt
> >501 CHMOD: Mode value must be between 0 and 0777

> >octal 100644 and not octal 0644.

> >        &send( sprintf( "SITE CHMOD %o $path", $mode ) );

> >When I change the line to:

> >        &send( sprintf( "SITE CHMOD 0644 $path", $mode ) );

> >everything works fine, but It's sick to code such silly things :-)

> OK... You need to remove the upper bits. Bitwise and is very nice for
> that.

>         &send( sprintf( "SITE CHMOD %o $path", 0777 & $mode ) );



Sat, 15 May 2004 09:38:00 GMT  
 Problems with Mirror - ftp.pl doesn't get the right octal for chmod

Quote:

>thanx for your efforts to solve my problem.
>I tested

>    &send( sprintf( "SITE CHMOD %o %s", $mode, $path ) );

>and got the same effect:
>---> SITE CHMOD 100644 Testfile.txt
>501 CHMOD: Mode value must be between 0 and 0777

>Tests with Bart's:

>        &send( sprintf( "SITE CHMOD %o $path", 0777 & $mode ) );

>worked fine.

You should combine the two.

        &send( sprintf( "SITE CHMOD %o %s", 0777 & $mode, $path ) );

It's safer.

--
        Bart.



Sat, 15 May 2004 14:26:05 GMT  
 
 [ 13 post ] 

 Relevant Pages 

1. win32 ftp'put problem with ftp.pl

2. Q: mirror.pl and cern ftp-proxy ?

3. 'chmod 755 xxx.pl'

4. Mirror (mirror ftp sites)

5. Net::FTP can't chmod!?

6. Net::FTP can't chmod!?

7. If/ Else doesn't work right....

8. a2p doesn't handle multiline record processing right

9. Why doesn't this work right?

10. System call doesn't work right!

11. Help: problem with ftp.pl and chat2.pl

12. perl FTP client problem (re: mirroring archives)

 

 
Powered by phpBB® Forum Software