Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Net::SFTP ssh_args => [ ] syntax question...

Reply
Thread Tools

Net::SFTP ssh_args => [ ] syntax question...

 
 
Icari
Guest
Posts: n/a
 
      08-18-2004
I am fairly new to Perl this being my first scripting project so I'm
still in my 'baby-talk' stage, but any suggestions/input would be most
helpful!

There's an example psftp script in the Net::SFTP module directory
which defines the following argument hash to pass into sftp:

my %args = (ssh_args => []); # from the perl man pages, it looks like
# ssh_args can be any arguments
# accepted by Net::SSH, so I guess
# I can put a hash list within
# a hash?

I wasn't able to run that script cleanly to test if my Net::SFTP
module was installed correctly so I wrote a smaller script to test:

#!/usr/local/bin/perl
use strict;

use Net::SFTP;

<$host, $user and $pass definined here>
my %args = (user => "$user", password => "$pass");
my $sftp = Net::SFTP->new($host, %args);
$sftp->put("testfile", "/var/tmp/remotetest");

When I ran my transfer program, it exits with a complaint that it does
not know what port 'ssh' is and made reference to the Net::SSH:erl
pm file...

I added ssh port 22 in my /etc/services file to temporarily fix this,
but I am really curious as to how I can define the ssh port within my
argument hash?

my %args = (user => "$user", password => "$pass", ssh_args => [port =>
22]);

Is the above right? I don't see the [ ] signs used too often outside
of pattern class definitions, the only time I saw this was with slices
so I'm not sure what the correct way to input additional ssh arguments
into the ssh_args option.

Thanks,
Icari.
 
Reply With Quote
 
 
 
 
David K. Wall
Guest
Posts: n/a
 
      08-19-2004
Icari <(E-Mail Removed)> wrote in message
<news:(E-Mail Removed). com>:

> There's an example psftp script in the Net::SFTP module directory
> which defines the following argument hash to pass into sftp:
>
> my %args = (ssh_args => []); # from the perl man pages, it looks
> like
> # ssh_args can be any arguments
> # accepted by Net::SSH, so I guess
> # I can put a hash list within
> # a hash?


I'm not sure I understand the question, plus you mention Net::SSH
when Net::SFTP uses Net::SSH:erl instead of Net::SSH. But, yes, you
can put a hash inside the anonymous array following 'ssh_args', e.g.;

my %params = ( port => 22 );
my %args = (ssh_args => [%params]);

But that's a rather long-winded way of doing it, and in my opinion
it's a bit obfuscated. More plainly: yecch!

> I wasn't able to run that script cleanly to test if my Net::SFTP
> module was installed correctly so I wrote a smaller script to
> test:
>
> #!/usr/local/bin/perl
> use strict;
>
> use Net::SFTP;
>
><$host, $user and $pass definined here>
> my %args = (user => "$user", password => "$pass");
> my $sftp = Net::SFTP->new($host, %args);
> $sftp->put("testfile", "/var/tmp/remotetest");
>
> When I ran my transfer program, it exits with a complaint that it
> does not know what port 'ssh' is and made reference to the
> Net::SSH:erl pm file...


The docs for Net::SFTP also refer you to Net::SSH:erl....

> I added ssh port 22 in my /etc/services file to temporarily fix
> this, but I am really curious as to how I can define the ssh port
> within my argument hash?


It seems you read the docs for Net::SFTP and Net::SSH:erl, because
the code below defines the ssh port just as the docs recommend. But
ssh_args is not really associated with a hash, but a scalar: a
reference to an anonymous array. You might benefit from reading
perlreftut and perlref. In particular, see "Make Rule 2" in
perlreftut.

> my %args = (user => "$user", password => "$pass", ssh_args =>
> [port => 22]);


$user and $pass don't need to have quotes around them, though. See
'perldoc -q quoting' for why this is generally a bad idea.

> Is the above right? I don't see the [ ] signs used too often
> outside of pattern class definitions, the only time I saw this was
> with slices so I'm not sure what the correct way to input
> additional ssh arguments into the ssh_args option.


The docs call for a reference to a list of named arguments; [] is the
most convenient way to write this. If you also wanted to turn on
compression, here's one way to write it:

my $sftp = Net::SFTP->new( $host,
user => $user,
password => $pass,
ssh_args => [port => 22, compression => 1]
);

Caveat: I've never used Net::SFTP, the above code is untested and
based purely on a quick reading of the docs.

--
David Wall
 
Reply With Quote
 
 
 
 
Icari
Guest
Posts: n/a
 
      08-19-2004
"David K. Wall" <(E-Mail Removed)> wrote in message news:<Xns954A6923E8A64dkwwashere@216.168.3.30>...
>
> I'm not sure I understand the question, plus you mention Net::SSH
> when Net::SFTP uses Net::SSH:erl instead of Net::SSH. But, yes, you
> can put a hash inside the anonymous array following 'ssh_args', e.g.;
>
> my %params = ( port => 22 );
> my %args = (ssh_args => [%params]);
>
> But that's a rather long-winded way of doing it, and in my opinion
> it's a bit obfuscated. More plainly: yecch!
> The docs for Net::SFTP also refer you to Net::SSH:erl....
> It seems you read the docs for Net::SFTP and Net::SSH:erl, because
> the code below defines the ssh port just as the docs recommend. But
> ssh_args is not really associated with a hash, but a scalar: a
> reference to an anonymous array. You might benefit from reading
> perlreftut and perlref. In particular, see "Make Rule 2" in
> perlreftut.
>
> > my %args = (user => "$user", password => "$pass", ssh_args =>
> > [port => 22]);

>
> $user and $pass don't need to have quotes around them, though. See
> 'perldoc -q quoting' for why this is generally a bad idea.
>
> The docs call for a reference to a list of named arguments; [] is the
> most convenient way to write this. If you also wanted to turn on
> compression, here's one way to write it:
>
> my $sftp = Net::SFTP->new( $host,
> user => $user,
> password => $pass,
> ssh_args => [port => 22, compression => 1]
> );
>
> Caveat: I've never used Net::SFTP, the above code is untested and
> based purely on a quick reading of the docs.


Oops, I actually did mean Net::SSH:erl. I read the man pages for
both SFTP and SSH-Perl modules, but was a bit confused with the syntax
usage when I saw the ssh_args => [ ] line in the example file. I just
tested this out and it worked, I won't need to worry about making sure
/etc/services had ssh port defined when I port my script to another
system. Thanks for your help . I was just recently placed on a
project to provide some scripts and just started to learn perl while I
was creating my code (I have not been coding for a long time) so I'm
still learning. I'll refer to the perlreftut and perlref for more
information, thanks again for all the tips!

Icari.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Syntax Checker that's better than the normal syntax checker Jacob Grover Ruby 5 07-18-2008 05:07 AM
Syntax error? What syntax error? Assignment fo default values? Mark Richards Perl Misc 3 11-18-2007 05:01 PM
Syntax bug, in 1.8.5? return not (some expr) <-- syntax error vsreturn (not (some expr)) <-- fine Good Night Moon Ruby 9 07-25-2007 04:51 PM
[ANN] SqlStatement 1.0.0 - hide the syntax of SQL behind familiarruby syntax Ken Bloom Ruby 3 10-09-2006 06:46 PM
Syntax highligth with textile: Syntax+RedCloth ? gabriele renzi Ruby 2 12-31-2005 02:44 AM



Advertisments