Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Need help: perl script to FTP

Reply
Thread Tools

Need help: perl script to FTP

 
 
FLOTServer
Guest
Posts: n/a
 
      08-26-2004
Here's my problem: I run a gameserver that runs the game "Medal of Honor".
On the game server is log file which contains all of the data from the
players for that day (kills, deaths, etc...). I have a perl script that runs
on my webserver, which is supposed to login to the gameserver and download
the log. The problem is that when it gets to the part where it needs to
download the file, it aborts. The gameserver FTP requires I use port 24 and
passive mode. Here's my script:

====start
#!/usr/bin/perl

##Game server IP
$ftpserver = "66.36.252.88:24";

##Login username
$ftpusername = "username";

##Login password
$ftppass = "password";

##Logfile folder on Game Server (no trailing slash)
$cwdd = "/mainta";

##Logfile name on the gameserver
$logfile = "qconsole.log";

##Logfile name saved on the webserver
$logname = "qconsole.log";

##Local path on webserver (no trailing slash)
$logpath = "/public_html/mohstats/logs";



##NO NEED TO EDIT ANYTHING BELOW THIS LINE

use Net::FTP;

if ($ftp = Net::FTP->new("$ftpserver", Debug => 0)) { print "Logging in to
server\n"; } else { print "could not find server! Exiting\n";
&send("Transfer FAILED. Could NOT connect to $ftpserver", "Transfer
FAILED"); exit; }

if ($ftp->login("$ftpusername","$ftppass")) { print "Username and Password
ACCEPTED\n"; } else { print "could not log into server with Username and
Password. Exiting!\n"; &send("Transfer FAILED. Could NOT connect to
$ftpserver with the Username And Password provided - Authentication error.",
"Transfer FAILED"); exit; }

if ($ftp->pasv) { print "Passive mode entered successfully\n"; } else {
print "Could not switch to pasive mode.\n"; }

if ($ftp->cwd("$cwdd")) { print "Changed to the directory without any
trouble - DOWNLOADING\n"; } else { print "Could not change to the
appropriate directory, uploading anyway\n"; }

if ($ftp->ascii) { print "Changed to ASCII Mode No Problem\n"; } else {
print "Could not change to ASCII mode $!\n"; exit; }

if ($ftp->get("$logfile","$logpath/$logname")) { print "Everything appears
ok with the Transfer\n"; } else { print "Can not Transfer file $!\n
EXITING\n", $ftp->message, "\n"; &send("Transfer FAILED. Could NOT Transfer
from $ftpserver. Error message returned from server is: $1", "Transfer
FAILED"); exit; }

$ftp->delete("$logfile");
$ftp->quit;

print "File Transferred OK!\nFinished\n";
====end

Here's the error I get when the script runs:

Undefined subroutine &main::send called at
/home/flot/public_html/cgi-bin/ftp.pl line 40.
Logging in to server
Username and Password ACCEPTED
Passive mode entered successfully
Changed to the directory without any trouble - DOWNLOADING
Can not Transfer file
EXITING
Cannot retrieve. Failed. Aborting

Any idea what is going wrong?

--
Visit the .FLOT|:. Spearhead Server at 66.36.252.88!
http://www.flotserver.net


 
Reply With Quote
 
 
 
 
Chris Cole
Guest
Posts: n/a
 
      08-26-2004
On Thu, 26 Aug 2004 00:21:53 -0400, FLOTServer wrote:

> Here's my problem: I run a gameserver that runs the game "Medal of Honor".
> On the game server is log file which contains all of the data from the
> players for that day (kills, deaths, etc...). I have a perl script that runs
> on my webserver, which is supposed to login to the gameserver and download
> the log. The problem is that when it gets to the part where it needs to
> download the file, it aborts. The gameserver FTP requires I use port 24 and
> passive mode. Here's my script:
>
> ====start
> #!/usr/bin/perl


use warnings;
use strict;

> ##Game server IP
> $ftpserver = "66.36.252.88:24";
>
> ##Login username
> $ftpusername = "username";
>
> ##Login password
> $ftppass = "password";
>
> ##Logfile folder on Game Server (no trailing slash)
> $cwdd = "/mainta";
>
> ##Logfile name on the gameserver
> $logfile = "qconsole.log";
>
> ##Logfile name saved on the webserver
> $logname = "qconsole.log";
>
> ##Local path on webserver (no trailing slash)
> $logpath = "/public_html/mohstats/logs";
>
>
>
> ##NO NEED TO EDIT ANYTHING BELOW THIS LINE
>
> use Net::FTP;
>
> if ($ftp = Net::FTP->new("$ftpserver", Debug => 0)) { print "Logging in to
> server\n"; } else { print "could not find server! Exiting\n";
> &send("Transfer FAILED. Could NOT connect to $ftpserver", "Transfer
> FAILED"); exit; }
>
> if ($ftp->login("$ftpusername","$ftppass")) { print "Username and Password
> ACCEPTED\n"; } else { print "could not log into server with Username and
> Password. Exiting!\n"; &send("Transfer FAILED. Could NOT connect to


The &send() subroutine doesn't exist in your script. Did you copy the
script from somewhere? Also, '&' is unecessary, send("blah...") is
sufficient.

> $ftpserver with the Username And Password provided - Authentication error.",
> "Transfer FAILED"); exit; }
>
> if ($ftp->pasv) { print "Passive mode entered successfully\n"; } else {
> print "Could not switch to pasive mode.\n"; }
>
> if ($ftp->cwd("$cwdd")) { print "Changed to the directory without any
> trouble - DOWNLOADING\n"; } else { print "Could not change to the
> appropriate directory, uploading anyway\n"; }
>
> if ($ftp->ascii) { print "Changed to ASCII Mode No Problem\n"; } else {
> print "Could not change to ASCII mode $!\n"; exit; }
>
> if ($ftp->get("$logfile","$logpath/$logname")) { print "Everything appears
> ok with the Transfer\n"; } else { print "Can not Transfer file $!\n
> EXITING\n", $ftp->message, "\n"; &send("Transfer FAILED. Could NOT Transfer
> from $ftpserver. Error message returned from server is: $1", "Transfer
> FAILED"); exit; }
>
> $ftp->delete("$logfile");
> $ftp->quit;
>
> print "File Transferred OK!\nFinished\n";
> ====end
>
> Here's the error I get when the script runs:
>
> Undefined subroutine &main::send called at
> /home/flot/public_html/cgi-bin/ftp.pl line 40.


See above for problem here

> Logging in to server
> Username and Password ACCEPTED
> Passive mode entered successfully
> Changed to the directory without any trouble - DOWNLOADING


OK up to here.

> Can not Transfer file
> EXITING
> Cannot retrieve. Failed. Aborting


Have you checked whether the file you're looking for exists? Do you have
write permission to your local directory?

> Any idea what is going wrong?


 
Reply With Quote
 
 
 
 
FLOTServer
Guest
Posts: n/a
 
      08-26-2004
"Chris Cole" <(E-Mail Removed)> wrote in message
news(E-Mail Removed)...
> > #!/usr/bin/perl

>
> use warnings;
> use strict;


I assume I am just adding these 2 lines below the first line?

> > if ($ftp->login("$ftpusername","$ftppass")) { print "Username and

Password
> > ACCEPTED\n"; } else { print "could not log into server with Username and
> > Password. Exiting!\n"; &send("Transfer FAILED. Could NOT connect to

>
> The &send() subroutine doesn't exist in your script. Did you copy the
> script from somewhere? Also, '&' is unecessary, send("blah...") is
> sufficient.


Yeah, I did copy it from somewhere. I'm not sure I understand your first
comment... about the $send() subroutine not existing. Can you elaborate? I'm
sorry, but I'm a big time noob when it comes to this stuff.

> > Can not Transfer file
> > EXITING
> > Cannot retrieve. Failed. Aborting

>
> Have you checked whether the file you're looking for exists? Do you have
> write permission to your local directory?


Yes, I do have permission to get the file and it is there. I can download it
manually with Smart FTP, but not with the perl script.

--
Visit the .FLOT|:. Spearhead Server at 66.36.252.88!
http://www.flotserver.net


 
Reply With Quote
 
Chris Cole
Guest
Posts: n/a
 
      08-27-2004
On Thu, 26 Aug 2004 11:37:19 -0400, FLOTServer wrote:

<Followup-To set as perl.beginners>

> "Chris Cole" <(E-Mail Removed)> wrote in message
> news(E-Mail Removed)...
>> > #!/usr/bin/perl

>>
>> use warnings;
>> use strict;

>
> I assume I am just adding these 2 lines below the first line?


Yes and no. Yes you can just add them in, but then your script won't work
as a whole bunch of errors will need to be addressed. It may seem like a
lot of work to get rid of the errors, but in the long run your perl
scripts will run more reliably. Read up on them.


>> > if ($ftp->login("$ftpusername","$ftppass")) { print "Username and

> Password
>> > ACCEPTED\n"; } else { print "could not log into server with Username
>> > and Password. Exiting!\n"; &send("Transfer FAILED. Could NOT connect
>> > to

>>
>> The &send() subroutine doesn't exist in your script. Did you copy the
>> script from somewhere? Also, '&' is unecessary, send("blah...") is
>> sufficient.

>
> Yeah, I did copy it from somewhere. I'm not sure I understand your first
> comment... about the $send() subroutine not existing. Can you elaborate?
> I'm sorry, but I'm a big time noob when it comes to this stuff.


Let's re-format part of your script for clarity:

if ($ftp->get("$logfile","$logpath/$logname")) {
print "Everything appears ok with the Transfer\n";
} else {
print "Can not Transfer file $!\nEXITING\n", $ftp->message, "\n";
&send("Transfer FAILED. Could NOT Transfer from $ftpserver. Error
message returned from server is: $1", "Transfer
FAILED");
exit;
}

the '&send("Transfer FAILED....");' command in the else block is calling a
subroutine called send(). There should be in the script a bit of code
starting 'sub send { some code }' and which runs whenever it is run. There
isn't in what you posted and that's why you're getting one of the error
messages ('Undefined subroutine &main::send'). Obviously I've no idea what
it should be doing, but if you can't find where you copied the script from
I think it's safe to remove both the &send() commands from the script.

>> > Can not Transfer file
>> > EXITING
>> > Cannot retrieve. Failed. Aborting

>>
>> Have you checked whether the file you're looking for exists? Do you
>> have write permission to your local directory?

>
> Yes, I do have permission to get the file and it is there. I can
> download it manually with Smart FTP, but not with the perl script.


No, what mean is does the script have permission to write to your
webserver in '/public_html/mohstats/logs'? Also have you checked your logs
for error messages? See google if you don't know which ones.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Execute another perl script from my perl script Petterson Mikael Perl Misc 3 01-05-2005 01:31 PM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM
problem calling perl script from SOAP server perl script pj Perl Misc 3 04-09-2004 10:23 PM
Perl Help - Windows Perl script accessing a Unix perl Script dpackwood Perl 3 09-30-2003 02:56 AM
How to make Perl Script "POST" call from another Perl Script??? Wet Basement Perl 1 07-15-2003 10:25 PM



Advertisments