4

I want to execute the tftp command without entering into the "tftp command line".

I have tried the below commands:

tftp xx.xx.xx.xx -c put file1 file2
tftp xx.xx.xx.xx -m binary -c file1 file2

But I got:

usage:tftp host-name [port]
tftp>

After the "usage:" message its entering the tftp command line.

I have tried it with the verbose option turned on.

I just want to know if the command I given worked properly. The "usage:" message makes it seem like it's not the correct usage of the tftp command.

This command is to be invoked from a Bash file which will be invoked from a CLI application I am working on.

I have followed the advices on this link : https://superuser.com/questions/581812/put-file-with-tftp-client-in-linux

runner
  • 155
  • 1
  • 2
  • 7

1 Answers1

5

You can use heredoc (<<) to enter the commands to execute one after another:

tftp host <<'EOF'
Enter
Commands
Here
EOF

Example:

$ tftp localhost <<'EOF'
> ascii
> status
> quit
> EOF

tftp> tftp> Connected to localhost.
Mode: netascii Verbose: off Tracing: off
Rexmt-interval: 5 seconds, Max-timeout: 25 seconds
tftp> 

$ 

If you desired tftp command is

get file1 /home/foobar/test.txt

you can do:

$ tftp host <<'EOF'
> get file1 /home/foobar/test.txt
> quit
> EOF
heemayl
  • 90,425
  • 20
  • 200
  • 267
  • I tried it as "**tftp -c get file1 /home/test.txt << quit**" but no activity noted here. no test.txt file created at home – runner Mar 23 '16 at 05:02
  • @runner at first just enter `tftp host <<'EOF'` at first, then press enter and move on to the next ones..check my edits – heemayl Mar 23 '16 at 05:08
  • Actually I want to invoke this from an another cli. so this entire command will be in another bash file. I executed with the commands you gave me. but its still entering **tftp** command line – runner Mar 23 '16 at 06:13
  • can you suggest how can i provide these commands in a bash file in order to avoid entering tftp command line – runner Mar 23 '16 at 06:14
  • @runner The commands go line by line in the script..just do it like my first snippet.. – heemayl Mar 23 '16 at 12:09