By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,852 Members | 2,220 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,852 IT Pros & Developers. It's quick & easy.

error in simulating an ftp client in perl

P: 1
i am using array to store a command given at run time by user... and execute it.....but after a connection is made to any ftp sites only 'ls' or 'dir' commands work....and if i wish to change directory or get any file or put file.example
get("123.mp3")
put("abc.txt")
cd user
etc or any commands that has space in between
then it gives error.wat i cn do to get or put files ...


Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2.  
  3. use Net::FTP;
  4.  
  5.         print("\nHost\/IP: ");
  6.         $host = <STDIN>;
  7.         chomp ($host);
  8.  
  9.         print("\nUsername: ");
  10.         $username = <STDIN>;
  11.         chomp ($username);
  12.     print "Password: ";
  13.     chop ($password = <STDIN>);
  14.     `stty echo`;
  15.     print "\n";
  16.  
  17.  print("Connecting to $host...\n");
  18.  my $ftp = Net::FTP->new($host) or die "Couldn't connect to $host\n";
  19.  print("Connected!\n");
  20.  print("\nFTP>");
  21.  
  22.  $ftp->login($username, $password)
  23.  or die "Could not log in .\n";
  24.  
  25.  rep:
  26.  
  27.  $command = <STDIN>;
  28.  
  29.  chomp ($command);
  30.  
  31.  unless ("$command" eq "bye") {      
  32.  
  33.  
  34.                   @listing = $ftp->$command;
  35.  
  36.                   for($i=0;$i<@listing;$i++) { print "$listing[$i]\n"; }
  37.  
  38.                   print("FTP>");
  39.  
  40.                   goto rep;
  41.  
  42.                                }
  43.  
Attached Files
File Type: txt ftp.txt (944 Bytes, 322 views)
May 1 '10 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.