473,386 Members | 1,924 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Need help: perl script to FTP

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
Jul 19 '05 #1
3 15263
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?


Jul 19 '05 #2
"Chris Cole" <it*******@gmail.com> wrote in message
news:pa****************************@gmail.com...
#!/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
Jul 19 '05 #3
On Thu, 26 Aug 2004 11:37:19 -0400, FLOTServer wrote:

<Followup-To set as perl.beginners>
"Chris Cole" <it*******@gmail.com> wrote in message
news:pa****************************@gmail.com...
> #!/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.
Jul 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: David K. Worman | last post by:
So this is probably a simple thing I'm missing, but then I just started working with perl tonight - and of course I bought the Camel book, and conveniently left it at work on my desk where it does...
3
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then...
3
by: xrongor | last post by:
hi. i need a simple, hopefully free html editor that besides the standard features has the following properties: allows frames. and will allow me to create a "directory" based on data...
3
by: Sol Linderstein | last post by:
Hi, I'm writing a CGI application and here's what I'm stuck with. There are some text boxes in an html form that I want to validate. The validation needs to happen on the server side because the...
20
by: mike | last post by:
I help manage a large web site, one that has over 600 html pages... It's a reference site for ham radio folks and as an example, one page indexes over 1.8 gb of on-line PDF documents. The site...
2
by: MK | last post by:
Hello, I am new to XML and PERL and I have a few questions the answers to which I need to complete a project. All your time and effort would be highly appreciated. I have to make a small HTML page...
3
by: uzzi | last post by:
I don't know how to make a php script to work via cron...I want to make it run daily...My server API is CGI/Fast CGI.I have hosting from godaddy and in the help section i found that i have to specify...
6
by: Paulchen | last post by:
Hello, I have found a perl script and need to "translate" this to PHP. I try to do it step by step and the first part of it is this function (the whole script is found at...
1
by: vikjohn | last post by:
I have a new perl script sent to me which is a revision of the one I am currently running. The permissions are the same on each, the paths are correct but I am getting the infamous : The specified...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.