shelltftp

Create a bash file for transfer file through tftp


I want to create shell script to invoke tftp transfer of particular file to my local machine

this is the operation i want to do

tftp 172.2.22.2
get file1_in_remote location file2_in_local_machine
quit

but I can't make it work, because when the 1st tftp command executes, control will got to tftp prompt. its just loook like this

tftp>

And it wont accept the 2nd and 3rd commands i have given in the shell script.

but when I exit from the tftp prompt, bash prints an error message like

get: command not found
quit: command not found

So How can I get it done

EDIT1:

tftp 173.32.52.12 -c get MyFile1.txt MyFile2.txt
tftp 173.32.52.12 -c get MyFile1.txt MyFile2.txt MyFile3.txt etc. etc.

these 2 commands not working with my ubuntu(14.0.4) system


Solution

  • I found the solution.

    file1_in_remote location = "/tftpboot/file1.txt"
    file2_in_local_machine = "/home/file2.txt"
    
    tftp 172.2.22.2 << !
    #file names can be stored in varible
    get ${file1_in_remote location} ${file2_in_local_machine}     
    quit
    !
    

    This worked for me

    And There is one more solution

    tftp 172.2.22.2 << 'EOF'
    #explictely specify the file names. varibales wont accept here.
    get /tftpboot/file1.txt /home/file2.txt  
    quit
    EOF
    

    but in second solution you have to give the file location explicit. And in the 1st solution file name can be stored in variable and we can use that variable in the "get" command.