I have several files named as this:
TEST_YYYYMMDD.txt
I need to upload them via ftp
, so to get the list of files I run:
files=($(ls | grep -i -E 'TEST_[0-9]{8}.txt'))
Now that I got the file list, how can I put
them via ftp
?
function upload() {
list="$1"
length=${#list[*]}
for ((i=0;i<=$(($length - 1)); i++))
do
ftp -n host << EOF
quote USER user
quote PASS password
prompt
put ${list[$i]}
quit
EOF
done
}
This would open a connection for each file.
Anyone could give me a better implementation?
mput
I don't know how to use it. .TEST_*
as wildcard isn't safe for me.
Thank you
Here how I've solved it
function upload() {
list="$1"
$user="username"
$password="password"
length=${#list[*]}
echo "open host user $user $password
binary
cd folder" > tmp/ftp.$$
for ((i=0;i<=$(($length- 1)); i++))
do
echo "put ${list[$i]}" >> tmp/ftp.$$
done
echo "quit" >> tmp/ftp.$$
ftp -ivn < tmp/ftp.$$
rm /tmp/ftp.$$
}