Koozali.org: home of the SME Server

Legacy Forums => General Discussion (Legacy) => Topic started by: Dave Liquorice on June 23, 2003, 07:12:51 PM

Title: Perl & FTP
Post by: Dave Liquorice on June 23, 2003, 07:12:51 PM
Hi,

Trying to write a Perl script to automate the updating of a remotely hosted website. I have this working under REXX on an OS/2 box at the moment but wish to move it to my SME 5.6u4 server.

I gets lots of errors even with this simple bit of Perl:

#!/usr/bin/perl -w
require "ftp.pl";
$host='some.host.com';
$result=&ftp'open($host,21,0,2);

5 or so "Ambiguous call resolved as ..." coming from both ftp.pl and chat2.pl. I guess the first thing is that call to &ftp'open() correct?

Looking about on the web newer versions of Perl use net::ftp rather than ftp.pl (which looks a damn sight easier to use). So two questions: Is SME v6 going to use a newer version of Perl and thus the net::ftp module meaning I'm wasting my time trying to get this to work with an older Perl?

Should I be attempting to do this in Perl or would Python be better?  I choose Perl because I know it and suggest Python as I spotted some modules related to FTP and Python on the disc. But I  know nothing of Python...

Cheers
Dave.
Title: Re: Perl & FTP
Post by: Charlie Brady on June 23, 2003, 08:45:02 PM
Dave Liquorice wrote:

> I gets lots of errors even with this simple bit of Perl:
>
> #!/usr/bin/perl -w
> require "ftp.pl";
> $host='some.host.com';
> $result=&ftp'open($host,21,0,2);

That's very old perl syntax.

> Looking about on the web newer versions of Perl use net::ftp
> rather than ftp.pl (which looks a damn sight easier to use).

You should use Net::FTP. ftp.pl is *ancient*.

> So two questions: Is SME v6 going to use a newer version of
> Perl and thus the net::ftp module meaning I'm wasting my time
> trying to get this to work with an older Perl?

No version of e-smith/SME ever used perl version 4, so you should use Net::FTP.

> Should I be attempting to do this in Perl or would Python be
> better?

That's a religious question :-) But either can get the job done.

Charlie
Title: Re: Perl & FTP
Post by: Dave Liquorice on June 24, 2003, 03:54:00 AM
Hi Charlie,

> You should use Net::FTP. ftp.pl is *ancient*.

I got that impression from the web last night but as I didn't find the relevant files on my 5.6u4 box thought that it was a moderately recent change and SME was erring on the side of caution as it normally does .

If It try a quick test prog I get back  "Can't locate Net/FTP.pm in @INC (@INC contains: {very long list...}" so I guess I need to add something to the box to get Net::FTP.

Tries "locate ftp.pm":
/usr/lib/perl5/vendor_perl/5.6.1/URI/ftp.pm
/usr/lib/perl5/vendor_perl/5.6.1/LWP/Protocol/ftp.pm

/usr/lib/perl5/vendor_perl/5.6.1/Net only contains HTTP.pm  HTTPS.pm and a HTTP directory.

Dumb questions but I  hope it beats telling people the SME6.0beta is *beta* not production code and to report bugs etc to the correct e-mail address.  B-)

Cheers
Dave.
Title: Re: Perl & FTP
Post by: Charlie Brady on June 24, 2003, 06:44:57 PM
Dave Liquorice wrote:
> I
> guess I need to add something to the box to get Net::FTP.

perl-libnet RPM.

> I  hope it beats telling people the
> SME6.0beta is *beta* not production code and to report bugs
> etc to the correct e-mail address.

Feel free to help :-)

Charlie
Title: Re: Perl & FTP
Post by: Dave Liquorice on June 26, 2003, 02:58:23 AM
>> I guess I need to add something to the box to get Net::FTP.
>
> perl-libnet RPM.

Got that from CPAN, installed it ran my test script, "Bad file descriptor" when trying to connect. Search the web, not a lot of use, begining to get the feeling of banging head against brick wall. Tries a different (remote) site rather than one on my LAN, it works. B-)  Can't figure why I can't FTP from SME to this other local machine, using FTP gives  "Connected to...  421 Service not available,..." but from my OS/2 box on the same LAN I can FTP into that machine....

Now I need a friendly editor, vi/vim I don't understand, pico makes me nervous (screen jumps instead of scrolling, $ signs appear when lines are scrolled of screen left or right)., mc's editor is OK but two many keypresses to start editing. Hope the latest Joe is stable...  B-)

Cheers
Dave.
Title: Re: Perl & FTP
Post by: Richard on July 01, 2003, 08:43:37 AM
This is running on my 5.6 box
#!/usr/bin/perl -w
use Net::FTP;
use File::Listing;
$thehost = 'domain.com';
$thedir = '/some/directory/to/change/to';
$ftp = Net::FTP->new($thehost, Timeout => 60) or die "Cannot contact $thehost : $!";
$ftp->login('user','password') or die "Can't login to $thehost" . $ftp->message;
$ftp->binary();
$ftp->cwd($thedir)or die "Change directory failed" . $ftp->message;
     foreach $file (parse_dir('ls -lR')) {
     print "\nIn the loop.\n";
     my($name, $type, $size, $mtime, $mode) = @$file;
     next unless $type eq 'f';
     print "Retrieving ", $name, "\n";
     $ftp->get($name) or warn "Couldn't get '$name', skipped: $!";
}
$ftp->quit();

I got this from http://www.samag.com/documents/s=1282/sam01030007/
Title: Re: Perl & FTP
Post by: Richard on July 01, 2003, 08:46:08 AM
This is running on my 5.6 box
#!/usr/bin/perl -w
use Net::FTP;
use File::Listing;
$thehost = 'domain.com';
$thedir = '/some/directory/to/change/to';
$ftp = Net::FTP->new($thehost, Timeout => 60) or die "Cannot contact $thehost : $!";
$ftp->login('user','password') or die "Can't login to $thehost" . $ftp->message;
$ftp->binary();
$ftp->cwd($thedir)or die "Change directory failed" . $ftp->message;
     foreach $file (parse_dir('ls -lR')) {
     print "\nIn the loop.\n";
     my($name, $type, $size, $mtime, $mode) = @$file;
     next unless $type eq 'f';
     print "Retrieving ", $name, "\n";
     $ftp->get($name) or warn "Couldn't get '$name', skipped: $!";
}
$ftp->quit();

I got this from http://www.samag.com/documents/s=1282/sam01030007/