Solved

Invoking tftp from within user space program

Posted on 2004-08-18
8
232 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 250 total points
ID: 11838595

tftp localhost << EOF
get kris123
EOF
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Linux script help 27 246
Prestashop 1.5 Redirect Problem 1 103
how can i fully uninstall a puppet client? 2 102
How to ssh into my virtual box linux machine 4 142
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 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…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

867 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

12 Experts available now in Live!

Get 1:1 Help Now