Hi, I am having trouble trying to figure out why the line: $get_xml->unlink($rem_name) or die "Couldn't remove $there: $!"; dies with the following error in the code below: "Couldn't remove /tmp/ssh2_test/testing/create_dirs.pl: Inappropriate ioctl for device at ssh2_testing.pl line 64." What would be the appropriate ioctl? The docs state that the only argument is file. The user being used to connect to the remote server has the proper permissions to remove the file noted in the above error message. The script works as it should up until the unlink call. Does anyone have any insight or ideas as to what I might need to change to get the unlink working? Thanks! use strict; use warnings; use Net::SSH2; my $rem_host = 'xxx.xxx.xxx.xxx'; my $rem_dir = '/tmp/ssh2_test/testing'; my $username = 'username'; my $password = 'password'; my $local_dir = '/export/scripts/xxx/temp/testing'; my (%xml_list, $rem_name, $rem_size, $v); ## connect to remote server with perl and ssh2 module ## my $ssh2 = Net::SSH2->new(); $ssh2->connect($rem_host) or die "Could not connect to $rem_host: $!"; $ssh2->auth_password($username,$password) or die "Could not login to $rem_host: $!"; ## uncomment line below to turn on debugging. ## $ssh2->debug(1); ## open sftp object ## my $get_xml = $ssh2->sftp(); ## get list of files in the /Outbound dir ## my $list = $get_xml->opendir($rem_dir) or die "Couldn't open dir $rem_dir: $!"; while (my $ref = $list->read()) { next if ( $ref->{name} =~ m/^\.\.?/ ); next if ( $ref->{size} =~ m/4096/ ); ## exclude dirs print "name: $ref->{name}\n"; print "size: $ref->{size}\n"; $rem_name = $ref->{name}; my $there = "$rem_dir/$rem_name"; my $here = "$local_dir/$rem_name"; open WRITE_LOCAL_FILE,">$here" or die "Couldn't open $here: $!"; sleep(1); ## read $rem_file and write locally ## my $open_rem_file = $get_xml->open($there) or die "Couldn't open $there: $!"; my $buff; while ( $open_rem_file->read($buff,4096) ) { print WRITE_LOCAL_FILE $buff; } close WRITE_LOCAL_FILE; ## code to remove the downloaded file ## $get_xml->unlink($rem_name) or die "Couldn't remove $there: $!"; } $ssh2->disconnect() or die "Couldn't do disconnect on ssh2: $!";

In reply to Net::SSH2 unlink trouble. by ncalsmitty1369

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.