ncalsmitty1369 has asked for the wisdom of the Perl Monks concerning the following question:
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: $!";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Net::SSH2 unlink trouble.
by apl (Monsignor) on Feb 13, 2008 at 02:09 UTC | |
by ncalsmitty1369 (Initiate) on Feb 13, 2008 at 20:51 UTC |