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:
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; }
EDIT:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.