Solved

C++ Mac Os X read file from ftp

Posted on 2004-04-08
6
273 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
ODBC Connection Logging, ADO.NET 6 49
deburging in oracle form 12 76
ORA-01403: no data found 43 82
countEvens challenge 2 58
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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.

708 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now