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

I need to transfer some 100 files into my remote directory in to the other machine..And i have develop a script that could done my task !...This script will read all the content of files in the local directory then transfered it one-by-one. After transferd one file, these file will be removed..And the provcess will go on until all the files are transfered and remove successfull ..Below is my script...
use Net::SSH::Perl; use Net::SFTP; $host = '***.***.***.***'; $username = '****'; $passwd = '****'; $remote_path = '/home/roime/'; $local_path = '/flow/flow'; chdir $local_path or die "Could Not Change Dir To $local_path!"; opendir(FILE, $local_path) || die("Cannot open directory"); @files=readdir(FILE); closedir(FILE); foreach $file(@files) { next if(-d $file); next if($file eq ".flow"); { $sftp=Net::SFTP->new($host, user => $username, password => $passwd, debug => 0) or die "Cannot connect to $host:$@"; $sftp->put("$file", "$remote_path") or die "...problem !..."; $sftp->ls($remote_path); unlink("$local_path$file") or die "having trouble deleting $file:$!";; print "$file deleted success....\n"; } } sub usage { my($name) = $0; $name =~ s/.*\///; print STDERR "Usage: $name <host> <username> <passwd> <remote_path> <l +ocal_path>\n"; exit; }
After i execute it, i receive this error message and I really need somebody opinion about this error...Thanks... Couldn't get handle: Failure at /usr/lib/perl5/site_perl/5.8.0/Net/SFTP.pm line 168. Couldn't write to remote file: Failure at /usr/lib/perl5/site_perl/5.8.0/Net/SFTP.pm line 263. Couldn't close file: No such file or directory at /usr/lib/perl5/site_perl/5.8.0/Net/SFTP.pm line 203. ...problem !... at rput.pl line 40.

Replies are listed 'Best First'.
Re: Net::SFTP In Linux ....... Error
by sasikumar (Monk) on Dec 16, 2004 at 05:50 UTC
    Hi
    Please try to ftp a single file. One more as per the
    Net::SFTP we need to give the complete path along with the
    file name that has to be created.

    Uploads a file $local from the local host to the remote host, and saves it as $remote.

    Try this way
    $file="/flow/flow/tmp.txt"; $remote_path="/home/roime/tmp.txt"; $sftp->put("$file", "$remote_path") or die "...problem!...";


    Thanks
    Sasi kumar