Why do you want to avoid the use of Net::FTP? I certainly think it would be the best tool for the job.
You said you found the code you quote on perlmonks, but you don't tell us where, and you only quote a small excerpt of the code. After some super-searching, it turns out the script you found is meant to connect to a ftp server through a firewall - it depends on the gateway having specific functionality.
If you absolutely refuse to have anything to do with Net::FTP (why? Why? WHY?), perhaps you could use Expect; and talk to the FTP prompts through that. | [reply] |
Ok! I have decided to use the Net::FTP::Common module
But, when I execute my code, I get the error
error logging in: at /usr1/duser/ActivePerl-5.8/lib/site_perl/5.8.2/Net/FTP/Common.pm line 127.
Can't call method "cwd" on an undefined value at /usr1/duser/ActivePerl-5.8/lib/site_perl/5.8.2/Net/FTP/Common.pm line 276.
Is it a problem with my code or with the installation of the module? But, after installation of the module I got a message "Successfully installed Net-FTP-Common version 3.7 in ActivePerl 5.8.2.808."
Here is my code
use Net::FTP::Common;
my $common_cfg = { Host => 'ftp.servername.com',
User => 'username',
Pass => 'password',
RemoteDir => '/files'
};
my $ftp = Net::FTP::Common->new($common_cfg, Debug => 0);
$ftp->get("somefile.txt");
$ftp->quit;
| [reply] [d/l] |
Provide problems, and we (try to) provide solutions, that's how perlmonks works. If you just told us your problems with Net::FTP at your first post, everyone had benefits out of it: you would have had the solution, and others would not have wasted their time trying to guess what the problem was and how to solve it
Update: By the way, when you are going to use objects in Perl it's always better to check that you really have one before trying to use it. I mean:
use Net::FTP;
# this is wrong, because you cwd without checking
# if $ftp is really an object or it is undef
# (new() failed)
$ftp = Net::FTP->new("some.host.name", Debug => 0) ;
$ftp->cwd("/pub") ;
# This is right instead, and it comes straight from
# Net::FTP's documentation
# See how every method call is checked for success
$ftp = Net::FTP->new("some.host.name", Debug => 0)
or die "Cannot connect to some.host.name: $@";
$ftp->login("anonymous",'-anonymous@')
or die "Cannot login ", $ftp->message;
$ftp->cwd("/pub")
or die "Cannot change working directory ", $ftp->message;
$ftp->get("that.file")
or die "get failed ", $ftp->message;
$ftp->quit;
Ciao --bronto
The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
--John M. Dlugosz
| [reply] [d/l] |
use strict;
use Net::FTP;
my $client = Net::FTP->new('ftp.servername.com', Debug => 1)
or die "Cannot connect : $@\n";
$client->cwd('/files') or die $client->message();
$client->get('somefile.txt') or die $client->message();
$client->quit()
/J\
| [reply] [d/l] |
[...]this is working code with some modified names.
I doubt that very much, as you declare two lexical variables with the same name (or one variable twice, depends on how you see the problem ,), namely $gsRemoteMachine.
You should RTFM of your ftp-client and/or RTF ftp-protocol-rfc (rfc 959).
Maybe an introductory perl-text would also prove helpful, you could check the Tutorials...
But why would you want to avoid to use a proven core(?) module?
regards,
tomte
An intellectual is someone whose mind watches itself. -- Albert Camus
| [reply] [d/l] |
| [reply] [d/l] |