csftpteam has asked for the wisdom of the Perl Monks concerning the following question:

Hello,

I'm trying to put a file to an SFTP server using Net::SFTP::Foreign. When I try to put the file, it fails with this error:</p?

Couldn't setstat remote file (setstat)': File not found

Here is the code that I am using:

my $file_put = 0; foreach my $file (@file_globs){ foreach my $filepath (glob($local_dir.$file)) { next if (! -e $filepath); $filename = $filepath; #strip down file path to just get file name $filename =~ s/(.*\/)//; $sftp_connection->put($filepath, $remote_dir.$filename); if ($sftp_connection->error == 0){ &logEntry($args{'logfile'}, "$jobname--Putting remote file +: /".$remote_dir.$filename); $file_put = 1; } elsif ($sftp_connection->error != 0){ &logEntry($args{'logfile'}, "$jobname-ERROR: ".$sftp_conne +ction->error); } } }

$remote_dir is set to "/to_commerce/" and $filepath is set to "/secureftp/jobhome/vendor/file.txt"

Anyone have any ideas why this error would be getting thrown? Please let me know if you need more info

Thanks!

Replies are listed 'Best First'.
Re: Net::SFTP::Foreign setstat Error on Put
by Eliya (Vicar) on Dec 16, 2011 at 18:59 UTC
    Couldn't setstat remote file (setstat)': File not found

    setstat is called to replicate attributes of the local file on the remote side, after having copied the file.  As you're getting "File not found" as the failure reason, I suspect the file might not have been created in the first place — perhaps due to a permission problem?

    You could try disabling setstat as described in the manual, to see if this really is the problem (in which case you still wouldn't succeed copying the file, but probably be getting a different error), or if the problem is somehow with the setstat method itself.

      Thanks Eliya! That worked!