Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Invoking tftp from within user space program

Posted on 2004-08-18
8
Medium Priority
?
257 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
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 1000 total points
ID: 11838595

tftp localhost << EOF
get kris123
EOF
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

885 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