Solved

Invoking tftp from within user space program

Posted on 2004-08-18
8
228 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
Comment Utility
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
Comment Utility
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
Comment Utility

tftp localhost << EOF
get kris123
EOF
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 

Author Comment

by:syamkris
Comment Utility
Thanks, it helps.
0
 
LVL 23

Expert Comment

by:brettmjohnson
Comment Utility
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
Comment Utility
#!/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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now