WhiskeyJack has asked for the wisdom of the Perl Monks concerning the following question:
Hello monks,
I'm a beginner with perl so I was hoping one of you could help me with my problem. I've created a program that connects to an sftp server and sends a file to it or gets one from it. What I would like to do is create a command line interface where the user of the program defines what the username password and host name of the server is and which file should be copied to it or from it in the CLI. So running the program would look something like this: program.pl -host -user -pass -location of program to copy.
This is the code I have so far:EDIT:use Net::SSH2; $open=$ARGV[0]; if ($open eq "connect"){ my $ssh2 = Net::SSH2->new(); $ssh2->connect($host) or die; if ($ssh2->auth_password($user, $pass)) { print "Authorization successful\n"; $put=$ARGV[0]; $get=$ARGV[1]; # Send file if ($put eq "send") { $ssh2->scp_put("local file path","remote file path") or warn "Could not copy the file to the server"; } #Get file from server elsif ($get eq "get") { print "File Copied"; $ssh2->scp_get("remote file", "local file") or warn "Could not copy the file from the server"; } else { print "Error: Arguments entered must be either send or get\n"; exit; } } else { print "Authorization failure\n"; } } else { print "Error: Argument entered must be connect\n"; exit; }
Well dasgar was right all I needed to do was look through Getopt::Long and I found my answer. Thank you dasgar. For anybody else having problems just read about the Getopt::Long module its within the first couple of paragraphs that you find the answer.
Thank you dasgar!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: CLI with ARGV
by dasgar (Priest) on Aug 08, 2012 at 06:14 UTC | |
by WhiskeyJack (Initiate) on Aug 08, 2012 at 06:52 UTC | |
|
Re: CLI with ARGV
by influx (Beadle) on Aug 08, 2012 at 08:20 UTC | |
by WhiskeyJack (Initiate) on Aug 08, 2012 at 09:24 UTC | |
by 2teez (Vicar) on Aug 08, 2012 at 17:47 UTC | |
by WhiskeyJack (Initiate) on Aug 09, 2012 at 06:34 UTC |