Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

3 Answers 3

up vote 1 down vote accepted

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

#!/bin/sh

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>
quit
EOF
share|improve this answer
    
Perfect! Thanks for the help! –  Greg Apr 25 at 15:07
add comment

You might find this URL useful in shell scripting TFTP: http://www.unix.com/shell-programming-and-scripting/159848-redirect-output-shell-script-tftp.html

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

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:

binary
put bin1 
put bin2
put bin3
quit

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 127.0.0.1 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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.