Solved

Invoking tftp from within user space program

Posted on 2004-08-18
8
248 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
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 

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

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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 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