I'm trying to get a listing of all the files in a specific directory (/myfiles) and then sftp them to another server. The number of files will vary and so will their names -- they will look like this: Code Translation Table_c_Primary Relationship Type Code Translation Table_e_Transaction Type
I was trying to put all them into an array then do a while loop (based on count) with an sftp put command. However, I can't seem to get this string into an array.
Here is what I have:
export directory=`find -name *Table_\*`
IFS="./"
read -a filearry <<< "${directory}"
During testing only ${filearry[0]} is populated. Output of echo ${filearry[0]} is:
Code Translation Table_c_Primary Relationship Type
Code Translation Table_e_Transaction Type
Code Translation Table_f_Appeal Code
Code Translation Table_g_Campaign Codes
Code Translation Table_h_Designation Code
Code Translation Table_i_Designation Purpose
Code Translation Table_j_Address Types
Code Translation Table_k_Degree of Graduation
Code Translation Table_l_Relationship Type
Code Translation Table_m_Activity Role
Code Translation Table_n_Activity Status Club
Code Translation Table_o_Participation Category
Code Translation Table_p_Activity Status Organization
Code Translation Table_q_Restriciton Code
Code Translation Table_c_Primary Relationship Type
Edit: This needs to be an automated script kicked off by cron. I'm not forced into using sftp, but whatever way I use it has to be secure.
I ended up just simplifying the script to upload all the files in the directory no matter what the name is. I have the output going to a log file which is sent as an text email to a couple people in my office. The format of this email isn't great. All the files are listed on the same line making it hard to read -- Is this fixable?
if [ "$(ls -A $DIR)" ];
then
printf "=====================================================\n"
printf " $DIR contains files.\n"
printf "=====================================================\n"
sftp [email protected]:/upload <<EOF
put -r /myfolder/*
quit
EOF
printf "=====================================================\n"
printf "Done transfering files.\n"
printf "=====================================================\n"
else
printf "No files to upload in $DIR"
fi
mailx -s 'Document Feed' [email protected] < /var/log/docfeed.log
sftp
or would an alternative such asscp
(or evenrsync
) be acceptable?