Not only suggestion above but the whole idea of assigning to a variable first is flawed if there is any chance that a file should contain whitespace.
1. Simply use the glob to feed the for loop:
Note: using a variable name over an alias may also help remove unexpected results
Note 2: this method would also negate the need for altering IFS
2. Quote - Quote - Quote -- for the same reason as above, everywhere you have left $f unquoted allows for the potential of unexpected results
3. You are looking your home directory and creating a new file there (targets). This may not be an issue but would generally be a poor practice IMHO
4. You append each file name, without a path, to target and then read from target??
Code:
$ ls
file1
file2
file3
Assuming the above files are in your home directory and that the files are processed in the same order, file1 will be added and then a call to while loop to execute ftpH. Then file2 is added
so when while is called the first 'line' read is still file1 so call ftpH on this again and then next read will have file2 in 'line'. Lastly file3 is read in but while processes
from top down so file1 then file2 and lastly file3 are all passed to ftpH
You can probably see an issue with the logic here
5. Finally, the use of ~, $HOME and basename can all be avoided by simply cd'ing into your HOME directory prior to running the for loop