in reply to Re^4: sftp->do_write howto?
in thread sftp->do_write howto?
Here's a version with more testing code:
The output of the script:#!/usr/bin/perl # create a remote file, without creating a local file # use Net::SFTP; use Net::SFTP::Constants qw/:flags/; use strict; use warnings; my $filename = "testfile.dat"; my $file_data = "qwertyuiop"; my %args = ( user => 'insaniac', password => 'xxxx' ); #my $host = "moretrix.com"; my $host = "bear"; my $remote_path = 'not_allowed/'.$filename; my ($err_code, $err_mesg); print "Connecting to $host\n"; my $sftp; eval { $sftp = Net::SFTP->new($host,%args) }; ($err_code, $err_mesg) = $sftp->status; if($err_code){ print "Err_code:$err_code | err_mesg:$err_mesg\n"; exit $err_code }; print "Open $host:$remote_path\n"; my $remote_handle; eval { $remote_handle = $sftp->do_open($remote_path, SSH2_FXF_WRITE | SSH +2_FXF_CREAT) }; ($err_code, $err_mesg) = $sftp->status; if($err_code){ print "Err_code:$err_code | err_mesg:$err_mesg\n"; exit $err_code }; print "Write to remote file:\n$file_data\n"; eval { $sftp->do_write($remote_handle, 0, $file_data) }; ($err_code, $err_mesg) = $sftp->status; if($err_code){ print "Err_code:$err_code | err_mesg:$err_mesg\n"; exit $err_code }; print "Close remote file handle\n"; $sftp->do_close($remote_handle);
And the directory on the remote host is:Connecting to bear Open bear:not_allowed/testfile.dat Couldn't get handle: Permission denied at net_sftp.pl line 33 Err_code:3 | err_mesg:Permission denied
bear: [/home/insaniac]# ls -ld not_allowed/ d--------- 2 root root 4096 Sep 23 13:40 not_allowed/
HTH
to ask a question is a moment of shame
to remain ignorant is a lifelong shame
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^6: sftp->do_write howto?
by chrism01 (Friar) on Sep 27, 2005 at 06:12 UTC | |
by insaniac (Friar) on Sep 28, 2005 at 11:32 UTC | |
by insaniac (Friar) on Sep 28, 2005 at 11:58 UTC | |
by chrism01 (Friar) on Sep 30, 2005 at 02:08 UTC | |
by insaniac (Friar) on Sep 30, 2005 at 09:04 UTC |