FTP Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationFTP Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
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  
Old October 20th, 2003, 02:23 AM
Diyar Diyar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Singapore
Posts: 54 Diyar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 5
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

Reply With Quote
  #2  
Old October 21st, 2003, 09:47 AM
e4c5 e4c5 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Posts: 778 e4c5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 20 sec
Reputation Power: 5
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

Reply With Quote
  #3  
Old October 22nd, 2003, 01:36 AM
Diyar Diyar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Singapore
Posts: 54 Diyar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 10 m 54 sec
Reputation Power: 5
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

Reply With Quote
  #4  
Old October 23rd, 2003, 12:56 PM
e4c5 e4c5 is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2003
Posts: 778 e4c5 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 23 m 20 sec
Reputation Power: 5
it's called 'slurp' please refer man perlvar and man perlopentut for details

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationFTP Help > net::FTP. one works but not the other


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway