Solved

C++ Mac Os X read file from ftp

Posted on 2004-04-08
6
277 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 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
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
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

ScreenConnect 6.0 Free Trial

At ScreenConnect, partner feedback doesn't fall on deaf ears. We collected partner suggestions off of their virtual wish list and transformed them into one game-changing release: ScreenConnect 6.0. Explore all of the extras and enhancements for yourself!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 57
C++ BOOL WINAPI ReadFile fails on windows 10 when reading from USB cable 9 432
lucky13 challenge 11 145
Not needed 13 112
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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