Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using Perl to automate an FTP process

Status
Not open for further replies.

SaltyDuke

Programmer
Sep 18, 2002
140
IE
Hello

A friend wants to use FTP to transfer her files onto a server. This process is carried out from the command prompt of a WinXP machine over to a Linux server, so she has to type

ftp
open 123.456.789.123
bin
hash
put C:\file.file /some/dir/file.file
bye

I'm writing a Perl script to automate this process. It works as follows:
1. User enters filename (i.e. C:\file.file)
2. program puts filename into put command
3. program starts FTP
4. program Transfers file
5. everything's hunky-dory : )

However, i'm stuck between step 3 and 4: when I open FTP (as follows: "system('ftp');") I'm at another prompt and cannot issue any further "system" commands!

anyone know of a way around this? I'm thinking a batchfile might do it but i'm not sure...

Thanx in advance for any help
TheSaltyDuke


[pipe]
 
use Net::FTP;

$ftp = Net::FTP->new("$hostname") or die "Can't ftp to $hostname: $!";
$ftp->login("$user","$pass");

# get user input of filenames
foreach $file (<>) {
last if($file eq &quot;QUIT&quot;);
$ftp->put(&quot;$file&quot;);
}

$ftp->quit;

# program exits;
 
# get user input of filenames
foreach $file (<>) {
### NEED the chomp ###
chomp $file;
last if($file eq &quot;QUIT&quot;);
$ftp->put(&quot;$file&quot;);
}
 
ftp -? will give you all your answers

ftp -s if memory saerves means you can create a baych file which will handle all the I/O required.

Perl can do it using Net::FTP, or a number of other ways, but so will your OS

Just a thought
-Paul
 
Thanks loads everyone!!!

Last night I was trying to write the FTP commands into a .bat file and then kick that off using a system() call but to no avail! The solution presented here offer a much more graceful solution. And though it looks a little OOP (which i'm not used to), I reckon you've helped me solve the problem.

Again, thanx :)

TheSaltyDuke

[pipe]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top