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!
In reply to CLI with ARGV by WhiskeyJack
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |