Solved

C++ Mac Os X read file from ftp

Posted on 2004-04-08
6
289 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 50 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
Independent Software Vendors: 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

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!

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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.
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

734 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