LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-18-2006, 06:05 AM   #1
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Rep: Reputation: 15
help: Using FTP client from C/C++ code


Hello!

I searched the forum for the question and didn't find satisfactory answer. I want to use FTP client code from my C/C++ application. What is the easiest way to do so? I found description of ftp module on Inets Reference Manual http://www.erlang.org/doc/doc-5.5.2/...ion_frame.html. I don't know where does this module come from, how it is loaded into the kernel, is it working trough some ioctl? Is it possible to use it from the code?

Please, all I need is some meaningful direction to use FTP client from the code.

Best regards,
 
Old 12-18-2006, 11:06 AM   #2
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
That's an Erlang module; probably not what you want if you're looking to use C or C++. (Unless you're trying to write some C code as part of an Erlang project?)

Do you have to use the interactive features of FTP in your application, or do you just need to download a file? If it's the latter, you can call an external process like "wget" or "fetch" to download the file for you, then do whatever you need to to the file that results.
 
Old 12-18-2006, 11:43 AM   #3
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Original Poster
Rep: Reputation: 15
I'm working on the embedded device which would be upgraded with the file downloaded from some FTP server. It would first be downloaded to the memory and then written to the flash trough /dev/mtdblock or file system (I don't have enough flash to store it directly to the flash, so I have to be sure I can download file properly to the RAM before I delete current version from the flash and write new one). It would also be able to upload it's backup to the FTP server.

I will need the similar interfaces from the C++ code for the DNS client, TFTP client, SNTP client, ICMP, etc.

I'm new to the Linux. I previously worked on the VxWorks system where all this features were already provided.

Best regards,
 
Old 12-20-2006, 07:48 PM   #4
Denes
Member
 
Registered: Mar 2004
Distribution: CentOS 4.3/4.5
Posts: 72

Rep: Reputation: 15
DNS client is provided using the gethostbyname function. This function is also in VxWorks.

FTP client can be controlled via popen which you can use to spawn a process for the ftp client and a pipe that you can send commands to it. I have done the equivalent with a bash script so it should work in a C/C++ program. Check out wget or fetch though, like the previous poster indicates. You can use fork and one of the exec functions to pass command line parameters to them.

I don't know about SNTP, worst case is you may have to find an implementation but it should not be difficult.

TFTP client I am also not sure about. You may be able to do the same as with FTP.

ICMP is a low level error protocol, you should not have to worry about it, it should just work.

You do know that Linux is not hard real time? You may get some unexpected delays occasionally in your system. To solve this there are some real time extensions to Linux. Or you could try LynxOS, but it doesn't share the same driver model as Linux so you may have to port device drivers.
 
Old 12-21-2006, 01:17 AM   #5
Rostfrei
Member
 
Registered: Aug 2005
Location: Slovenia
Distribution: Fedora, Ubuntu
Posts: 69

Original Poster
Rep: Reputation: 15
Real time issue is really not so important here as it's about SIP phone application.

gethostbyname is not enough for me in some cases because I need to resolve the domain name into IP address and port as conforms to "RFC 3263 - Session Initiation Protocol (SIP): Locating SIP Servers"

What do you think about ICMP should just work? Is there some "ping" function in the net library I can use? I had something like ping from the code on VxWorks. I called the function and it returned the result (it was blocking function). I need it sometimes to check the presence of the network devices.

About FTP, TFTP client. I'm totally new to the popen and piping and sending command to the FTP client from the code. Can you direct me on some page where I can see some code? How can I download the file to the RAM first and not directly to the disk? I heard something about RAM disk (here I would have to do mounting from the code?).

Best regards,
 
Old 12-21-2006, 03:55 PM   #6
Denes
Member
 
Registered: Mar 2004
Distribution: CentOS 4.3/4.5
Posts: 72

Rep: Reputation: 15
I don't know how to get a port for a protocol over DNS so I couldn't help you there. Possibly spawning the nmap program can help you.

int retval = system("ping -c 1 192.168.0.1");

will do a system call and return a value for ping. This is just one use of ICMP.

Download Advanced Linux Programming (there is a free pdf available) and read the section 5.4.4 on popen. This has easy source code in it. I would recommend reading the whole book, it will enlighten you.

Example of script with ftp, you would use popen, and use fprintf on the descriptor instead. Normally I use variables here.

# Run FTP as a client, opening server at IPAddress
ftp -n 192.168.0.1 <<END_SCRIPT
# Send user name
quote USER anonymous
# Send password
quote PASS anything
# Change to binary mode
binary
# Change to directory where file is
cd FileDirectory
# Get the file
get File
# Exit FTP
quit
# End of FTP script portion
END_SCRIPT

Programming in Linux can be different from VxWorks in that VxWorks gives you C functions for protocols like TFTP and SNTP, whereas in Linux, you spawn applications (processes) and pass in parameters to do this for you.

I have never used a RAM disk in Linux. It may work but you may also want to look at shared memory, output redirection, fifo's, or pipes to see if one of these techniques will work with ftp.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Source Code for a simple ftp server and client koodoo Programming 17 07-05-2013 11:48 AM
ProFTPd ... FTP client fails to connect: timeout after client sends 'LIST' nutnut Linux - Software 2 01-01-2006 07:09 PM
What FTP client do you use? NonSumPisces Linux - Software 3 08-31-2004 11:24 AM
HELP!!!!! ftp client C4Spider Programming 4 10-11-2003 07:51 AM
ipchains, ftp from client to non-ftp ports atari303 Linux - Networking 2 11-08-2002 02:43 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:06 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration