Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm working on migrating my development environment from Windows to OS X and have run across a problem with TFTP. I use TFTP to upload files to an embedded network device, this is the only option to get the files on the device (no SCP support is provided).

Every time I build firmware for this device, there's a series of three files that need to be uploaded to it. On Windows I had some simple scripts that would upload all of the files I needed in one shot which makes deploying everything much simpler. These scripts were easy because the Windows TFTP client is run in one-line commands like this:

tftp -i <Server IP Address> PUT <Local Filename> <Server Filename>

It doesn't seem that there's any way to upload a file with one command like this on OS X. Instead, you have to open the tftp program and execute a series of commands that looks something like this:

$ tftp
tftp> connect <Server IP Address>
tftp> mode binary
tftp> put <Local Filename> <Server Filename>
tftp> quit

So far I have not had any luck in figuring out how to write a script to do this, although I don't have a ton of experience with Unix shell scripting. Has anyone tried to do anything similar and come up with any solutions?

share|improve this question
up vote 2 down vote accepted

You should be able to use a "here document" to feed commands to the tftp program in a script:


tftp <<EOF
connect <server IP Address>
mode binary
put <Local Filename 1> <Server Filename 1>
put <Local Filename 2> <Server Filename 2>
put <Local Filename 3> <Server Filename 3>
share|improve this answer
Perfect! Thanks for the help! – Greg Apr 25 '14 at 15:07

You might find this URL useful in shell scripting TFTP:

share|improve this answer
Thanks for pointing me to that article, I was able to get something working from there. – Greg Apr 25 '14 at 15:08

You can make a plain text script with the commands that you'd enter at the tftp> prompt, and then use the unix shell's stdin redirect to pass the commands to the tftp executable.

For example, into my /tmp/ directory, I put files bin1 bin2 and bin3.

I then used a text editor to make a file loader.txt with these contents:

put bin1 
put bin2
put bin3

Not having a TFTP server running, I used ttcp -r -u to open UDP port 5001, and watched to see if the file was being processed, when I executed the following in another window:

[Nevins-mac-mini:/tmp] nevin% tftp 5001 < loader.txt
Transfer timed out.

Transfer timed out.

Transfer timed out.

[Nevins-mac-mini:/tmp] nevin%

The timeouts were expected for my test case.

I verified that each file was offered in turn after the timeouts, and that they were being offered in binary, not ascii mode, so I'm confident that each line in loader.txt was parsed through the tftp binary.

I hope this helps...

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .