I have a script that connects to a remote sftp server and is then suppose to print a listing of all the files in the remote directory. However, I get the error message "Argument "\x{2e}" isn't numeric in hash element..". Can anyone tell from my code what I am doing incorrectly? I am on a FreeBSD v 5.3 R1 machine running Perl 5.8.5 (build for i386-freebsd-64int). I don't have much experience with Perl and would appreciate any help offered. My code is below and it errors out on the line "$filename=$file->{filename}". Quick note: The script does call another script (subroutines.pl) that contains subroutines that I use often, but that shouldn't have anything to do with the actual error (at least I don't think it would).
Thank you for your time!
#!/usr/bin/perl -w
$base_dir = substr($0,0,rindex($0,"/"));
chop($hostname = `hostname`);
# include shared subroutines
do "$base_dir/subroutines.pl";
$sftphost = "remote.sftpserver.net";
$sftpuser = "username";
$sftppass = "password";
$remotedir = "TO REMOTE";
($scriptname = "$0") =~ s/.*\///;
# begin log string
$outSTR = log_divider("BEGIN: (" . localtime() . ")");
$outSTR .= "$hostname : $scriptname - $subject\n";
# create string with name of log file based on $scriptname
$logfile= substr($scriptname,0,rindex($scriptname,".")) . ".log";
$log_dir= "$base_dir/log";
# Set up first log entry
$outSTR .= log_divider("Begin Test Connection Script");
print $outSTR;
log_it($log_dir,$logfile,$outSTR);
# Connect to remote SFTP server
$sftp = sftpf_connect($sftphost,$sftpuser,$sftppass);
# List remote directory contents
@$remotefiles=$sftp->ls($remotedir);
# Loop @$remotefiles and print each filename
foreach (@$remotefiles){
$file=$_;
$filename=$file->{filename};
if($filename ne "." && $filename ne ".."){
print"the filename is $filename";
}
}
#Disconnect from remote server
sftpf_disconnect($sftp);
# Write to log file
$outSTR .= log_divider("End Test Connection Script");
print $outSTR;
log_it($log_dir,$logfile,$outSTR);
print $outSTR;
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.