C++ Mac Os X read file from ftp

I'm working on Mac Os X c++ application that needs a function  to access a text file on a server, read it and append to it. Basically, I think I need a way to ftp to the site, read the file and then write to it. I've been looking at the CFFTP functions, but have not had any success. Does anyone have a relatively simple way to do this?
Who is Participating?
Karl Heinz KremerConnect With a Mentor Commented:
If you don't have access to a ftp component that you can use, you should look into calling the ftp program and providing input via a input script. The OS X ftp program allows you to specify user id and password on the commands line. All commands that need to be executed can then be provided via input redirection:

/usr/bin/ftp ftp://user:passwd@ftp.domain.com < commands

You can even open a pipe to the ftp command and provide the commands over the pipe (in this case you don't have to create the commands file).

First, you would download the file (after potentially switching to binary mode) you are interested in (e.g. /my/file.txt) to your local machine, then create a file that only contains the new information you want to append, and then call the append command with the local file name of the partial file and the remote file as arguments:

get /my/file.txt /local/path/to/file.txt

... create the update file
append /local/path/to/append.txt /my/file.txt

Karl Heinz KremerCommented:
Do you need more information?
csugrueAuthor Commented:
That's really good to know, but I need to do this inside a program, not from the command line. It just needs to poll the file periodically for info and use it elsewhere in the program... any ideas on frameworks or libraries would  be useful
Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

Karl Heinz KremerCommented:
As I said, you can do this from within a program: Just use the popen() system call. This will open a pipe to an external command.
csugrueAuthor Commented:
I see. so i can use popen() to execute the shell commands, right? that makes sense, I'll give it try.thanks!
Karl Heinz KremerCommented:
popen() or system() - depending on how you want to use the external command. popen() allows you to either write to the pipe or read from the pipe. In the case of teh input redirection, you want to read from the pipe to get error messages. If you are not interested in a specific error, just a general status from the command you can use system(). Again, here are the steps:

You first write out the command file (e.g. /tmp/ftp_commands.txt) containing the commands you would otherwise type while the ftp command is running, then you create your command line with the user name and password encoded like I described it earlier. Then you call either system() or popen() to actually execute the command.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.