Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

C++ Mac Os X read file from ftp

Posted on 2004-04-08
6
Medium Priority
?
308 Views
Last Modified: 2013-12-26
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?
0
Comment
Question by:csugrue
  • 4
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 150 total points
ID: 10796749
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:

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

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



0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10817892
Do you need more information?
0
 

Author Comment

by:csugrue
ID: 10825261
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
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10826045
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.
0
 

Author Comment

by:csugrue
ID: 10826797
I see. so i can use popen() to execute the shell commands, right? that makes sense, I'll give it try.thanks!
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10827242
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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Suggested Courses

927 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