You can pass commands to ftp through standard input. In a script you will end up with a here document
. For example:
/usr/bin/ftp -ni 10.10.10.10 <<-EOS
user comin weldone
You can put every permitted ftp command inside the here document. In my example I used the user
command to login. The binary
command to ensure a correct transfer of all types of files, the cd
command to go to the directory where you want to upload, the mput
statement and the bye
command to quit politely.
In a here document you can put shell variables or command substitutions to manage dynamic data. The shell will expand them before actually execute the ftp commands. Regarding the ftp option, I usually put -n to avoid the automatic login through the .netrc file (if any) and the -i option to prevent interactive prompting. This happens when you transfer multiple files and the ftp asks you confirmation about every file (in alternative you can use the prompt
command to toggle the interactive prompting on and off).
A security concern is that in this kind of script you have to write username and password in clear text. If someone with malicious intent has access to your script, he can do some damage to the remote server.
Hope this helps. See also man ftp for future reference.