Solved

Invoking tftp from within user space program

Posted on 2004-08-18
8
242 Views
Last Modified: 2010-04-22
Hi,

I would like to know how I can do a tftp download of a file from a remote machine within a user space program running on my machine. I can use "system" command in my C program, but because tftp is an interactive utility - it will not be of use.

Ideally, after the successful download of the file, I would also like to have the file descriptor of the downloaded file so that I can do some processing on the downloaded file.

I am constrained to use tftp only. If it is not possible at all, then I can think of ftp / rcp or some such stuff.

Your help is appreciated,
Krishna
0
Comment
Question by:syamkris
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 45

Expert Comment

by:sunnycoder
ID: 11838464
Hi syamkris,

>I can use "system" command in my C program, but because tftp is an interactive utility - it will not be of use.
you can write a tftp script and launch it from your program

The script will look like this

tftp << EOF        .... this tells the program to keep executing the commands in the script until EOF sequence is encountered
tftp command 1
tftp command 2
..
..
tftp command n
EOF

> Ideally, after the successful download of the file, I would also like to have the file
> descriptor of the downloaded file so that I can do some processing on the downloaded file.
You will have to open the file again ... You can use open() or fopen(), this should be trivial

Sunnycoder
0
 

Author Comment

by:syamkris
ID: 11838562
Hi,

I still couldn't understand how I can pass the parameters interactively using a shell script. I did the following. kris123 is a file which already exists in my /tftpboot on my system and I could successfully get it using a tftp from shell prompt.

[root@blru0119 root]# cat tftp.sh
#!/bin/sh
tftp << EOF
tftp localhost
get kris123
EOF

[root@blru0119 root]# sh tftp.sh
tftp> ?Invalid command
tftp> usage: get host:file host:file ... file, or
       get file file ... file if connected
tftp> [root@blru0119 root]#

May be if you explain more, it will help me better.

Thanks,
Kris
0
 
LVL 45

Accepted Solution

by:
sunnycoder earned 250 total points
ID: 11838595

tftp localhost << EOF
get kris123
EOF
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:syamkris
ID: 11838669
Thanks, it helps.
0
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 11842664
If you read the error message closely, you should be able to do:

tftp localhost:kris123

without any HERE i/o redirection.

0
 
LVL 5

Expert Comment

by:ITcrow
ID: 11866078
#!/bin/sh

{ echo "
open ftp.someserver.wherever
user anonymous anonymous@mars.nodomain
hash
cd /public/
get README
close
"
} | ftp -inv 2>&1 | tee ftp_session.log

Add any commands in the above program, as long as it works in interactive session.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
qos on linux 3 109
Google Mini is no longer serving everything 7 164
How to redirect a serial com to a KVM machine on Proxmox 3 502
Replication of Nagios surveilance data 2 103
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question