I am trying to upload a bunch of files to an ftp server via lfpt. For this I loop over the files and call the upload script with the file as argument. This works only for the first file.
Here's the code:
files=$(find "$dir" -maxdepth 1 -name "0025-*.PDF" -newer timestamp)
for file in "$files"
do
bash upload.sh "$file" ""
stat "$file" >> watchdog.log
done
And here the upload script:
#!/bin/bash
echo 'upload of file' "$1" 'will start now'
lftp -e "set ftp:passive-mode true; set ftp:ssl-allow true; set ftp:ssl-force true; set ftp:ssl-protect-data true; set ftp:ssl-protect-list true; set net:timeout 10;
open -u XXX,XXX XXX;
cd '$2';
sleep 2;
put '$1';
bye"
echo "$1" written to folder "$2"
The file paths contain spaces and after the first iteration I get the error of an unkown command showing the path until the space (e.g., Unkown command ´example/test'. ; original path: example/test 2/file1.pdf). What do I get wrong?