Advertisement
Guest User

Untitled

a guest
May 17th, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.13 KB | None | 0 0
  1. #!/usr/bin/perl
  2. use Net::FTP;
  3. use Switch;
  4. sub shell
  5. {
  6.     print "~# ";
  7.     chomp($input = <STDIN>);
  8.     switch( $input )
  9.     {
  10.         case ["help"] {
  11.             print "\nget: Download a file from remote host\npwd: Print working directory that exists on remote host\nrm: Remove a file from remote host\nput: Used for upload a file into remote host\nmdkir: Used for create a directory on remote host\nrmdir: Remove a remote directory\nrename: Rename a file of remote host\nls: Print the directory\n\n";
  12.             shell();
  13.         }
  14.         case ["exit"] {
  15.             print "\nbyz\n";
  16.             exit();
  17.         }
  18.         case ['get'] {
  19.             print "file name to get> ";
  20.             chomp($fname=<STDIN>);
  21.             $ftpclient->get($fname);
  22.             print "successfully transfered\n";
  23.             shell();
  24.         }
  25.         case ['pwd'] {
  26.             $pwd = $ftpclient->pwd();
  27.             print "$pwd\n";
  28.             shell();
  29.         }
  30.         case ['rm'] {
  31.             print "file name to delete> ";
  32.             chomp($dname=<STDIN>);
  33.             $ftpclient->delete($dname);
  34.             print "successfully removed\n";
  35.             shell();
  36.         }
  37.         case ['put'] {
  38.             print "file name to upload> ";
  39.             chomp($ufile=<STDIN>);
  40.             $ftpclient->put($ufile);
  41.             print "successfully uploaded\n";
  42.             shell();
  43.         }
  44.         case ['mkdir'] {
  45.             print "name of directory to create> ";
  46.             chomp($dirname=<STDIN>);
  47.             $ftpclient->mkdir($dirname);
  48.             print "directory successfully created\n";
  49.             shell();
  50.         }
  51.         case ['rmdir'] {
  52.             print "name of directory to remove> ";
  53.             chomp($deldirname=<STDIN>);
  54.             $ftpclient->rmdir($deldirname);
  55.             print "directory successfully removed\n";
  56.             shell();
  57.         }
  58.         case ['rename'] {
  59.             print "rename the file> ";
  60.             chomp($name1=<STDIN>);
  61.             print "rename the file ".$name1." with> ";
  62.             chomp($name2=<STDIN>);
  63.             $ftpclient->rename($file1,$file2);
  64.             print "file ".$file1." successfully renamed with ".$file2."\n";
  65.             shell();
  66.         }
  67.         case ['ls'] {          
  68.             my @directory = $ftp->ls();
  69.             foreach my $singola_dir( @directory )
  70.             {
  71.                 print $singola_dir, "\n";
  72.             }
  73.            
  74.             shell();
  75.         }
  76.     }
  77.     shell();
  78. }
  79. $hostname = $ARGV[0];
  80. $username = $ARGV[1];
  81. $password = $ARGV[2];
  82. $ftpclient = Net::FTP->new($hostname);
  83. $ftpclient -> login($username, $password);
  84. print "successfully connected!\n\n";
  85. shell();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement