Re: Which Net::FTP method for this?"

Re: Which Net::FTP method for this?"

am 08.11.2005 10:22:05 von metaperl

My CPAN module Net::FTP::Common executes a hard-coded series of
commands before every API call...

In retrospect, a cleaner approach might've been to provide support and
pre and post callbacks instead.

You can check out the code at search.cpan.org and modify at will. I'm
too busy these days to modify it for you.

Re: Which Net::FTP method for this?"

am 08.11.2005 15:59:14 von mailbox

metaperl@gmail.com wrote:
> You can check out the code at search.cpan.org and modify at will.

I did look at it, and it's an interesting product.

My query can probably be boiled down to this: why doesn't quot work for
cd? But I like to include context information to generate interest in
such a specialized question, even at the risk of eliciting unexpected
responses, such as the accusation elsewhere in the followups that I'm
trying to get others to do my work.

Anyway, the documenation for Net::FTP at CPAN says that quot works only
for "commands that do not require data connections". So my question can
be further boiled down to this: define "data connection" in such a way
that I can identify which FTP commands qualify and which do not.
(RFC959 is too abstract to be useful here.) Intuitively, I would expect
that get and put require a "data connection" and just about every other
command is for control.

Re: Which Net::FTP method for this?"

am 08.11.2005 15:59:14 von mailbox

metaperl@gmail.com wrote:
> You can check out the code at search.cpan.org and modify at will.

I did look at it, and it's an interesting product.

My query can probably be boiled down to this: why doesn't quot work for
cd? But I like to include context information to generate interest in
such a specialized question, even at the risk of eliciting unexpected
responses, such as the accusation elsewhere in the followups that I'm
trying to get others to do my work.

Anyway, the documenation for Net::FTP at CPAN says that quot works only
for "commands that do not require data connections". So my question can
be further boiled down to this: define "data connection" in such a way
that I can identify which FTP commands qualify and which do not.
(RFC959 is too abstract to be useful here.) Intuitively, I would expect
that get and put require a "data connection" and just about every other
command is for control.

Re: Which Net::FTP method for this?"

am 08.11.2005 23:44:52 von 1usa

mailbox@cpacker.org wrote in
news:1131461953.962804.164460@g49g2000cwa.googlegroups.com:

>
> metaperl@gmail.com wrote:
>> You can check out the code at search.cpan.org and modify at will.
>
> I did look at it, and it's an interesting product.
>
> My query can probably be boiled down to this: why doesn't quot work
> for cd? But I like to include context information to generate interest
> in such a specialized question, even at the risk of eliciting
> unexpected responses, such as the accusation elsewhere in the
> followups that I'm trying to get others to do my work.

Cute. Did you actually try fixing the error I pointed out in your script?

Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and
remove .invalid for email address)

comp.lang.perl.misc guidelines on
the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 08.11.2005 23:44:52 von 1usa

mailbox@cpacker.org wrote in
news:1131461953.962804.164460@g49g2000cwa.googlegroups.com:

>
> metaperl@gmail.com wrote:
>> You can check out the code at search.cpan.org and modify at will.
>
> I did look at it, and it's an interesting product.
>
> My query can probably be boiled down to this: why doesn't quot work
> for cd? But I like to include context information to generate interest
> in such a specialized question, even at the risk of eliciting
> unexpected responses, such as the accusation elsewhere in the
> followups that I'm trying to get others to do my work.

Cute. Did you actually try fixing the error I pointed out in your script?

Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and
remove .invalid for email address)

comp.lang.perl.misc guidelines on
the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 09.11.2005 01:50:44 von Sisyphus

wrote in message
..
..
> My query can probably be boiled down to this: why doesn't quot work for
> cd?

I think it's a case of "Why doesn't the FTP Server understand 'cd' ?" - and
that's an off-topic question on a perl forum. I'd answer that question
except that I don't know the correct answer :-)

Of course wrt 'cd' specifically, there's no *need* for the FTP Server to
understand it, as there's already the FTP commands (and Net::FTP methods)
'cwd' and 'cdup' to handle directory changes. They should be used instead.

> But I like to include context information to generate interest in
> such a specialized question, even at the risk of eliciting unexpected
> responses, such as the accusation elsewhere in the followups that I'm
> trying to get others to do my work.
>

Best to just ignore the inflammatory stuff and look for the *useful*
remarks. Sinan did recommend that you turn on debugging - and that's good
advice. (If you don't know how to do that, just specify Debug=>1 as one of
the arguments to the new() constructor - and you'll get more verbose
feedback from the FTP Server.) There's also a hint that the syntax of your
quot() call is incorrect .... but that one eludes me.

Basically, I gather that what you're wanting to do is to be able to execute
commands that are not supported by the FTP protocol.
You might find something useful on
http://cpan.uwinnipeg.ca/htdocs/libnet/libnetFAQ.html . Especially "How can
I change the permissions of a file on a remote server ?" and "Is it possible
to change the file permissions of a file on an FTP server ?" - both of which
provide slightly different ways of executing a command (chmod) that is not
supported by the FTP protocol. (Note that there's no guarantee that the FTP
Server will oblige - though both incantations worked with the FTP Server
that I use.)

I suspect that "the customer" may be harrassing the wrong person. If the FTP
Server doesn't understand some command, then there's nothing you can do
about it. You should simply tell "the customer" to take it up with the
person(s) in charge of the FTP Server.

Cheers,
Rob

Re: Which Net::FTP method for this?"

am 09.11.2005 01:50:44 von Sisyphus

wrote in message
..
..
> My query can probably be boiled down to this: why doesn't quot work for
> cd?

I think it's a case of "Why doesn't the FTP Server understand 'cd' ?" - and
that's an off-topic question on a perl forum. I'd answer that question
except that I don't know the correct answer :-)

Of course wrt 'cd' specifically, there's no *need* for the FTP Server to
understand it, as there's already the FTP commands (and Net::FTP methods)
'cwd' and 'cdup' to handle directory changes. They should be used instead.

> But I like to include context information to generate interest in
> such a specialized question, even at the risk of eliciting unexpected
> responses, such as the accusation elsewhere in the followups that I'm
> trying to get others to do my work.
>

Best to just ignore the inflammatory stuff and look for the *useful*
remarks. Sinan did recommend that you turn on debugging - and that's good
advice. (If you don't know how to do that, just specify Debug=>1 as one of
the arguments to the new() constructor - and you'll get more verbose
feedback from the FTP Server.) There's also a hint that the syntax of your
quot() call is incorrect .... but that one eludes me.

Basically, I gather that what you're wanting to do is to be able to execute
commands that are not supported by the FTP protocol.
You might find something useful on
http://cpan.uwinnipeg.ca/htdocs/libnet/libnetFAQ.html . Especially "How can
I change the permissions of a file on a remote server ?" and "Is it possible
to change the file permissions of a file on an FTP server ?" - both of which
provide slightly different ways of executing a command (chmod) that is not
supported by the FTP protocol. (Note that there's no guarantee that the FTP
Server will oblige - though both incantations worked with the FTP Server
that I use.)

I suspect that "the customer" may be harrassing the wrong person. If the FTP
Server doesn't understand some command, then there's nothing you can do
about it. You should simply tell "the customer" to take it up with the
person(s) in charge of the FTP Server.

Cheers,
Rob

Re: Which Net::FTP method for this?"

am 09.11.2005 02:23:38 von 1usa

"Sisyphus" wrote in
news:43714821$0$25852$afc38c87@news.optusnet.com.au:

> There's also a hint that the syntax of your quot() call is
> incorrect .... but that one eludes me.

Well, the docs say

:

quot (CMD [,ARGS])

whereas the OP is using:

quot("cd somedirectory")

according to his post.

Looking at the source for Net::FTP:

sub quot
{
my $ftp = shift;
my $cmd = shift;

$ftp->command( uc $cmd, @_);
$ftp->response();
}

So, passing the string "cd somedirectory" to quot would result in
"CD SOMEDIRECTORY" being sent to the server. I doubt that's what the OP
intended.

I am, of course, not sure if this will help, but without this error
fixed, I see no point in looking elsewhere.

Of course, actually turning debugging on for Net::FTP probably would
have revealed what was actually being sent to the server.

Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 09.11.2005 02:23:38 von 1usa

"Sisyphus" wrote in
news:43714821$0$25852$afc38c87@news.optusnet.com.au:

> There's also a hint that the syntax of your quot() call is
> incorrect .... but that one eludes me.

Well, the docs say

:

quot (CMD [,ARGS])

whereas the OP is using:

quot("cd somedirectory")

according to his post.

Looking at the source for Net::FTP:

sub quot
{
my $ftp = shift;
my $cmd = shift;

$ftp->command( uc $cmd, @_);
$ftp->response();
}

So, passing the string "cd somedirectory" to quot would result in
"CD SOMEDIRECTORY" being sent to the server. I doubt that's what the OP
intended.

I am, of course, not sure if this will help, but without this error
fixed, I see no point in looking elsewhere.

Of course, actually turning debugging on for Net::FTP probably would
have revealed what was actually being sent to the server.

Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 09.11.2005 03:08:35 von Sisyphus

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
..
..
>
> Of course, actually turning debugging on for Net::FTP probably would
> have revealed what was actually being sent to the server.
>

It also gives you an error message from the server (which you otherwise
don't see):

Net::FTP=GLOB(0x921f28)>>> CD w32perl
Net::FTP=GLOB(0x921f28)<<< 500 CD not understood

For me, there is no correct way to do a 'cd' using Net::FTP. I tried:

$ftp->quot("site cd", "w32perl");
$ftp->quot("cd", "w32perl");
$ftp->quot("site cd w32perl");
$ftp->quot("cd w32perl");
$ftp->site("cd", "w32perl");
$ftp->site("cd w32perl");

Although the actual command varied, it always produced "500 not
understood".

When I look at the libnet faq I find the following examples (both of which
work for me):
$ftp->quot('site chmod 0777',$filename);
$ftp->site('chmod','0775',$file);

Note that in the first of those two commands '0777' is part of the CMD - it
is *not* provided as an argument.

From the Net::FTP documentation, I would have expected that the quot() call
be written as:
$ftp->quot('chmod', '0777', $filename);
But that produces, for me:
Net::FTP=GLOB(0x921f34)<<< 500 CHMOD not understood

However, the following works fine:
$ftp->quot('site chmod', '0777',$filename);

Note that this time '0777' *is* being provided as an argument.

My hunch is that quot('site cd somedirectory') would work just as well as
quot('site cd', 'somedirectory') .... except that 'cd' is not supported (on
the FTP Server I use, at least - with or without the 'site') .... which
makes that conjecture a little absurd :-)

Incidentally, to the op:
A return of 5 is short for 500 (basically means error, I think), a return of
2 is short for 200 (basically means ok, I think).

Cheers,
Rob

Re: Which Net::FTP method for this?"

am 09.11.2005 03:08:35 von Sisyphus

"A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
..
..
>
> Of course, actually turning debugging on for Net::FTP probably would
> have revealed what was actually being sent to the server.
>

It also gives you an error message from the server (which you otherwise
don't see):

Net::FTP=GLOB(0x921f28)>>> CD w32perl
Net::FTP=GLOB(0x921f28)<<< 500 CD not understood

For me, there is no correct way to do a 'cd' using Net::FTP. I tried:

$ftp->quot("site cd", "w32perl");
$ftp->quot("cd", "w32perl");
$ftp->quot("site cd w32perl");
$ftp->quot("cd w32perl");
$ftp->site("cd", "w32perl");
$ftp->site("cd w32perl");

Although the actual command varied, it always produced "500 not
understood".

When I look at the libnet faq I find the following examples (both of which
work for me):
$ftp->quot('site chmod 0777',$filename);
$ftp->site('chmod','0775',$file);

Note that in the first of those two commands '0777' is part of the CMD - it
is *not* provided as an argument.

From the Net::FTP documentation, I would have expected that the quot() call
be written as:
$ftp->quot('chmod', '0777', $filename);
But that produces, for me:
Net::FTP=GLOB(0x921f34)<<< 500 CHMOD not understood

However, the following works fine:
$ftp->quot('site chmod', '0777',$filename);

Note that this time '0777' *is* being provided as an argument.

My hunch is that quot('site cd somedirectory') would work just as well as
quot('site cd', 'somedirectory') .... except that 'cd' is not supported (on
the FTP Server I use, at least - with or without the 'site') .... which
makes that conjecture a little absurd :-)

Incidentally, to the op:
A return of 5 is short for 500 (basically means error, I think), a return of
2 is short for 200 (basically means ok, I think).

Cheers,
Rob

Re: Which Net::FTP method for this?"

am 09.11.2005 03:34:13 von 1usa

"Sisyphus" wrote in
news:43715a60$0$22779$afc38c87@news.optusnet.com.au:

> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
> .
> .
>>
>> Of course, actually turning debugging on for Net::FTP probably would
>> have revealed what was actually being sent to the server.
>>
>
> It also gives you an error message from the server (which you
> otherwise don't see):
>
> Net::FTP=GLOB(0x921f28)>>> CD w32perl
> Net::FTP=GLOB(0x921f28)<<< 500 CD not understood
>
> For me, there is no correct way to do a 'cd' using Net::FTP. I tried:

Well, the only FTP server I have access to does not accept cd, but using

$ftp->quot(qw(cwd public_html));

works for me.

....

> When I look at the libnet faq I find the following examples (both of
> which work for me):
> $ftp->quot('site chmod 0777',$filename);
> $ftp->site('chmod','0775',$file);
>
> Note that in the first of those two commands '0777' is part of the CMD
> - it is *not* provided as an argument.
>
> From the Net::FTP documentation, I would have expected that the quot()
> call be written as:
> $ftp->quot('chmod', '0777', $filename);
> But that produces, for me:
> Net::FTP=GLOB(0x921f34)<<< 500 CHMOD not understood

Interesting. For me, that seems to work:

#!/usr/bin/perl

use strict;
use warnings;

my %account = (
host => '...',
name => '...',
pass => '...',
);

use Net::FTP;

my $ftp = Net::FTP->new($account{host}, Debug => 1)
or die "Cannot connect to '$account{host}': $@\n";

$ftp->login($account{name}, $account{pass})
or die "Cannot login: ", $ftp->message, "\n";

$ftp->quot(qw(site chmod 0777 test.txt));

$ftp->quit;

__END__

....
Net::FTP=GLOB(0x1a567a0)>>> SITE chmod 0777 test.txt
Net::FTP=GLOB(0x1a567a0)<<< 200 SITE CHMOD command successful
Net::FTP=GLOB(0x1a567a0)>>> QUIT
Net::FTP=GLOB(0x1a567a0)<<< 221 Goodbye.


> However, the following works fine:
> $ftp->quot('site chmod', '0777',$filename);
>
> Note that this time '0777' *is* being provided as an argument.

It should not make any difference, though. Net::FTP->quot uses
Net::CMD->command which joins all its arguments using a space.

....

> Incidentally, to the op:
> A return of 5 is short for 500 (basically means error, I think), a
> return of 2 is short for 200 (basically means ok, I think).

Which, of course, are explained by Net::FTP and RFC 959.

Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 09.11.2005 03:34:13 von 1usa

"Sisyphus" wrote in
news:43715a60$0$22779$afc38c87@news.optusnet.com.au:

> "A. Sinan Unur" <1usa@llenroc.ude.invalid> wrote in message
> .
> .
>>
>> Of course, actually turning debugging on for Net::FTP probably would
>> have revealed what was actually being sent to the server.
>>
>
> It also gives you an error message from the server (which you
> otherwise don't see):
>
> Net::FTP=GLOB(0x921f28)>>> CD w32perl
> Net::FTP=GLOB(0x921f28)<<< 500 CD not understood
>
> For me, there is no correct way to do a 'cd' using Net::FTP. I tried:

Well, the only FTP server I have access to does not accept cd, but using

$ftp->quot(qw(cwd public_html));

works for me.

....

> When I look at the libnet faq I find the following examples (both of
> which work for me):
> $ftp->quot('site chmod 0777',$filename);
> $ftp->site('chmod','0775',$file);
>
> Note that in the first of those two commands '0777' is part of the CMD
> - it is *not* provided as an argument.
>
> From the Net::FTP documentation, I would have expected that the quot()
> call be written as:
> $ftp->quot('chmod', '0777', $filename);
> But that produces, for me:
> Net::FTP=GLOB(0x921f34)<<< 500 CHMOD not understood

Interesting. For me, that seems to work:

#!/usr/bin/perl

use strict;
use warnings;

my %account = (
host => '...',
name => '...',
pass => '...',
);

use Net::FTP;

my $ftp = Net::FTP->new($account{host}, Debug => 1)
or die "Cannot connect to '$account{host}': $@\n";

$ftp->login($account{name}, $account{pass})
or die "Cannot login: ", $ftp->message, "\n";

$ftp->quot(qw(site chmod 0777 test.txt));

$ftp->quit;

__END__

....
Net::FTP=GLOB(0x1a567a0)>>> SITE chmod 0777 test.txt
Net::FTP=GLOB(0x1a567a0)<<< 200 SITE CHMOD command successful
Net::FTP=GLOB(0x1a567a0)>>> QUIT
Net::FTP=GLOB(0x1a567a0)<<< 221 Goodbye.


> However, the following works fine:
> $ftp->quot('site chmod', '0777',$filename);
>
> Note that this time '0777' *is* being provided as an argument.

It should not make any difference, though. Net::FTP->quot uses
Net::CMD->command which joins all its arguments using a space.

....

> Incidentally, to the op:
> A return of 5 is short for 500 (basically means error, I think), a
> return of 2 is short for 200 (basically means ok, I think).

Which, of course, are explained by Net::FTP and RFC 959.

Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 09.11.2005 20:39:44 von mailbox

A. Sinan Unur wrote:
> Well, the only FTP server I have access to does not accept cd, but using
>
> $ftp->quot(qw(cwd public_html));
>
> works for me.


I've never connected to an FTP server that didn't accept "cd" entered
at the prompt.

The customer wants me to be able to process an arbitrary series of
control commands fed to me as a single string before getting or putting
data, e.g. "sunique;site umask 022;cd somedirectory;". I had hoped to
be able to make successive quot calls, but I'll just have to
put in some extra code to process a "cd" either the way you've shown
above or with a call to the cwd function. A minor irritation in the
end, but I still wanted to make sure there was no more parsimonious
alternative.

Thanks to you and Sisyphus for being generous with your time in
checking out the situation.

Re: Which Net::FTP method for this?"

am 09.11.2005 20:39:44 von mailbox

A. Sinan Unur wrote:
> Well, the only FTP server I have access to does not accept cd, but using
>
> $ftp->quot(qw(cwd public_html));
>
> works for me.


I've never connected to an FTP server that didn't accept "cd" entered
at the prompt.

The customer wants me to be able to process an arbitrary series of
control commands fed to me as a single string before getting or putting
data, e.g. "sunique;site umask 022;cd somedirectory;". I had hoped to
be able to make successive quot calls, but I'll just have to
put in some extra code to process a "cd" either the way you've shown
above or with a call to the cwd function. A minor irritation in the
end, but I still wanted to make sure there was no more parsimonious
alternative.

Thanks to you and Sisyphus for being generous with your time in
checking out the situation.

Re: Which Net::FTP method for this?"

am 09.11.2005 20:54:28 von 1usa

mailbox@cpacker.org wrote in
news:1131565184.035727.92260@z14g2000cwz.googlegroups.com:

> The customer wants me to be able to process an arbitrary series of
> control commands fed to me as a single string before getting or
> putting data, e.g. "sunique;site umask 022;cd somedirectory;". I had
> hoped to be able to make successive quot calls,

You might benefit from using a different tool. Instead of Net::FTP, I
would look into Expect:



Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 09.11.2005 20:54:28 von 1usa

mailbox@cpacker.org wrote in
news:1131565184.035727.92260@z14g2000cwz.googlegroups.com:

> The customer wants me to be able to process an arbitrary series of
> control commands fed to me as a single string before getting or
> putting data, e.g. "sunique;site umask 022;cd somedirectory;". I had
> hoped to be able to make successive quot calls,

You might benefit from using a different tool. Instead of Net::FTP, I
would look into Expect:



Sinan
--
A. Sinan Unur <1usa@llenroc.ude.invalid>
(reverse each component and remove .invalid for email address)

comp.lang.perl.misc guidelines on the WWW:
http://mail.augustmail.com/~tadmc/clpmisc/clpmisc_guidelines .html

Re: Which Net::FTP method for this?"

am 10.11.2005 03:01:44 von samwyse

mailbox@cpacker.org wrote:
> A. Sinan Unur wrote:
>
>>Well, the only FTP server I have access to does not accept cd, but using
>>
>>$ftp->quot(qw(cwd public_html));
>>
>>works for me.
>
> I've never connected to an FTP server that didn't accept "cd" entered
> at the prompt.

On a related note, an FTP server that I use a lot recently stopped
accepting "mkdir" commands from my client. I'm not sure if it's a
client or a server problem, but using my client's "QUOTE MKD xyzzy"
command does work.

Re: Which Net::FTP method for this?"

am 10.11.2005 03:01:44 von samwyse

mailbox@cpacker.org wrote:
> A. Sinan Unur wrote:
>
>>Well, the only FTP server I have access to does not accept cd, but using
>>
>>$ftp->quot(qw(cwd public_html));
>>
>>works for me.
>
> I've never connected to an FTP server that didn't accept "cd" entered
> at the prompt.

On a related note, an FTP server that I use a lot recently stopped
accepting "mkdir" commands from my client. I'm not sure if it's a
client or a server problem, but using my client's "QUOTE MKD xyzzy"
command does work.

Re: Which Net::FTP method for this?"

am 11.11.2005 04:37:09 von unknown

mailbox@cpacker.org wrote:
> A. Sinan Unur wrote:
>
>>Well, the only FTP server I have access to does not accept cd, but using
>>
>>$ftp->quot(qw(cwd public_html));
>>
>>works for me.
>
>
>
> I've never connected to an FTP server that didn't accept "cd" entered
> at the prompt.
>

A more correct way to say this is "I've never used an FTP client that
didn't accept 'cd' entered at the prompt." What gets sent to the server
may be (and is in this case) something different.

> The customer wants me to be able to process an arbitrary series of
> control commands fed to me as a single string before getting or putting
> data, e.g. "sunique;site umask 022;cd somedirectory;". I had hoped to
> be able to make successive quot calls, but I'll just have to
> put in some extra code to process a "cd" either the way you've shown
> above or with a call to the cwd function. A minor irritation in the
> end, but I still wanted to make sure there was no more parsimonious
> alternative.
>
> Thanks to you and Sisyphus for being generous with your time in
> checking out the situation.
>

The problem appears to be that the customary commands to the FTP client
do not necessarily have the same names as the underlying FTP protocol
commands. Two alternatives: using the protocol names, or translating the
command names. The former would go something like this:

my $client = Net::FTP->new (...)

# ... some code to set things up ...

my $what_to_do = 'site umask o22;cwd somedirectory;'
foreach my $cmd (split ';', $what_to_do) {
next unless $cmd; # handle trailing ';'
my @args = split '\s+', $cmd;
my $verb = shift @args;
$client->$verb (@args); # Call method of your choice.
}


If you're getting fancy, you might want to use Text::ParseWords rather
than split().

Note that I called the relevant method via the contents of $verb. This
appears to work even if you have 'strict' and 'warnings' turned on. I
have not dealt with error trapping (hint: $client->can ($verb)).

But calling the commands what you want may not need to be all that
difficult:

my %alias = (cd => 'cwd');

and then, after determining the verb, do something like

$verb = $alias{$verb} if $alias{$verb};
The thing is, there are a number of the customary commands that simply
configure the client. And 'sunique' appears to be one of them. If I were
implementing it using Net::FTP, I would have it tell the client to use
put_unique() rather than put().

Tom Wyant

Re: Which Net::FTP method for this?"

am 11.11.2005 04:37:09 von unknown

mailbox@cpacker.org wrote:
> A. Sinan Unur wrote:
>
>>Well, the only FTP server I have access to does not accept cd, but using
>>
>>$ftp->quot(qw(cwd public_html));
>>
>>works for me.
>
>
>
> I've never connected to an FTP server that didn't accept "cd" entered
> at the prompt.
>

A more correct way to say this is "I've never used an FTP client that
didn't accept 'cd' entered at the prompt." What gets sent to the server
may be (and is in this case) something different.

> The customer wants me to be able to process an arbitrary series of
> control commands fed to me as a single string before getting or putting
> data, e.g. "sunique;site umask 022;cd somedirectory;". I had hoped to
> be able to make successive quot calls, but I'll just have to
> put in some extra code to process a "cd" either the way you've shown
> above or with a call to the cwd function. A minor irritation in the
> end, but I still wanted to make sure there was no more parsimonious
> alternative.
>
> Thanks to you and Sisyphus for being generous with your time in
> checking out the situation.
>

The problem appears to be that the customary commands to the FTP client
do not necessarily have the same names as the underlying FTP protocol
commands. Two alternatives: using the protocol names, or translating the
command names. The former would go something like this:

my $client = Net::FTP->new (...)

# ... some code to set things up ...

my $what_to_do = 'site umask o22;cwd somedirectory;'
foreach my $cmd (split ';', $what_to_do) {
next unless $cmd; # handle trailing ';'
my @args = split '\s+', $cmd;
my $verb = shift @args;
$client->$verb (@args); # Call method of your choice.
}


If you're getting fancy, you might want to use Text::ParseWords rather
than split().

Note that I called the relevant method via the contents of $verb. This
appears to work even if you have 'strict' and 'warnings' turned on. I
have not dealt with error trapping (hint: $client->can ($verb)).

But calling the commands what you want may not need to be all that
difficult:

my %alias = (cd => 'cwd');

and then, after determining the verb, do something like

$verb = $alias{$verb} if $alias{$verb};
The thing is, there are a number of the customary commands that simply
configure the client. And 'sunique' appears to be one of them. If I were
implementing it using Net::FTP, I would have it tell the client to use
put_unique() rather than put().

Tom Wyant