|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
|||
|
|||
|
net::FTP. one works but not the other
Its mind boggling for me to figure out how to get file using net::ftp in a menu format and by reading another file to get the ip , password and username. i did two similar codes.... one code which i want it to work doesnt work.... and the other code which works but its not my objective.
The objective is to prompt the user to enter source directory in the remote machine to where the file is, the it will display all the files in that directory, thenm it prompts the user to enter what file to get... and next, it promts the user to enter target directory(in the local server) to store the file. The below codes which i want it to works hang halfway after it prompts for the source directory. the user enter one, it will go to this subroutine Code:
sub openfile{
my $fileinit="/home/speg/transferfile.init";
print "Name of File read: $fileinit\n";
$/="---\n";
open(ALL,"$fileinit")or die"Couldnt read from $fileinit\n";
while(<ALL>){
chomp();
if ($_=~"SYNAX1"){
my @line=split("\n",$_);
print "\nSTAT: $_\n";
($name,$ip,$sd,$td,$wildcard,$username,$password,$buffer,$localbuffer)=@line;
&select1();
}
}close ALL;
}
sub select1{
print "Enter source directory:";
chomp($source_dir = <STDIN>);
print "\n\n";
$ftp = Net::FTP->new("$ip", Debug => 0)|| die "Cannot connect to $ip: $@";
$ftp->login("$username","$password")or die "Cannot login ", $ftp->message;
$ftp->cwd("$source_dir");
@list=$ftp->ls("$source_dir");
foreach(@list){
print"$_\n";
print "Enter file:";
chomp ($key = <STDIN>);
print "FILE:$key";
print "Enter local directory to store the file:";
chomp ($target_dir = <STDIN>);
print "\n\n";
$final="$target_dir\/$key";
$ftp->cwd("$source_dir");
$ftp->binary();
$ftp->get("$key","$final");
print "File Transfer Complete\n\n";
$ftp->quit;
&quit();
}
}
The another one below works... but not what i want, i want it to read the ip, password and username from an init file... but it confirms my theory suppose to works in the codes above... Code:
sub select1{
print "Enter source directory:";
chomp($source_dir=<STDIN>);
print "\n\n";
$ftp = Net::FTP->new("202.1.154.34", Debug => 0)|| die "Cannot connect to $ip: $@"; #CONNECT TO IP
$ftp->login("speg","update?")or die "Cannot login ", $ftp->message;
$ftp->cwd("$source_dir");
@list=$ftp->ls("$source_dir");
foreach(@list){
print"$_\n";
}
print "\n\nEnter file to get:";
chomp($key=<STDIN>);
print "\n\n";
print "Enter target directory to place:";
chomp($target_dir=<STDIN>);
print "\n\n";
$final="$target_dir\/$key";
$ftp->binary();
$ftp->get("$key","$final")||die"$!";
print "File Transfer Complete\n\n";
$ftp->quit;
&quit();
}
Need help and guidance. thanks Diyar
__________________
U go PERL.. perlomatic |
|
#2
|
|||
|
|||
|
Re: net::FTP. one works but not the other
Hi,
I am commenting without running your code, so i could be wrong, but i would guess that you are running into problems because you are reading user input and FTP server's IO streams on the same thread.
__________________
A lean and mean secure FTP applet with GUI. Just 150 kb in size http://www.radinks.com/sftp |
|
#3
|
|||
|
|||
|
hey... i found out my problem... its not because of that... it because of this code in the program.
Code:
$/="---\n"; The code above acts as a separator to read the init file below. Code:
SYNAX1 202.1.152.41 /logs/STDF /local/home/transfer/DATALOG/FT/STDF .stdf speg update? 6 21 --- SYNAX1 202.1.152.31 /logs/GDF /local/home/transfer/DATALOG/FT/GDF .gdf speg update? 6 12 --- SYNAX2 202.1.152.12 /logs/STDF /local/home/transfer/DATALOG/FT/STDF .stdf speg update? 6 21 --- SYNAX2 202.1.152.21 /logs/GDF /local/home/transfer/DATALOG/FT/GDF .gdf speg update? 6 12 --- SYNAX3 202.1.152.21 /logs/STDF /local/home/transfer/DATALOG/FT/STDF .stdf speg update? 6 21 --- but i still do not know how to solve it. what does $/ means? help. thanks |
|
#4
|
|||
|
|||
|
it's called 'slurp' please refer man perlvar and man perlopentut for details
|
![]() |
| Viewing: Dev Shed Forums > System Administration > FTP Help > net::FTP. one works but not the other |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|