LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 03-23-2005, 02:19 PM   #1
hansschmucker
LQ Newbie
 
Registered: Oct 2004
Posts: 27

Rep: Reputation: 15
Unhappy C -communicating with system("ftp"); using "program|ftp>>myfifo" probably


I've got a very simple program here for which I can't find a reasonable explanation. I need a program which generates a static index for an FTP server... generally not much of a problem... I just use system("cat script|ftp ftp://userass@server.com/path/>output.file"); with "script" containing nothing more then a simple "ls" and parse the resulting output.log.

Problem is, that requires me to re-login for each directory which takes some time, so I want to keep ftp running all the time and just issue some commands to it

Code:
int main(int argc, char *argv[])
{	
	UInt32 i;
	IndexType FileIndex;
	if(argc==1){
		fprintf(stderr,"Please start with\n mkindex ftp://user:pass@server.com/path/\n");
		return 1;
	}
	if(argv[1][1]!='i'){
		fprintf(stderr,"self launch");
		system(Str_Merge6(argv[0]," -i ",argv[1],"|ftp ",argv[1], "\n"));
		return 1;
	}
	fprintf(stdout,"ls\n ");
}
Problem is that ftp quits as soon as there are no more commands coming from the main program, instead of sitting there and waiting for the next command. If I issue a cd and an ls command while ftp is still busy loggin in, it'll execute both, but exit immediately afterwards, like it would get an EOF from the input. Any ideas how to solve this? Any help would be highly appreciated!
 
Old 03-23-2005, 02:39 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
I think popen() would be a much better solution to your problem. Check out the man page for it.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Telling people to use "Google," to "RTFM," or "Use the search feature" Ausar General 77 03-21-2010 12:26 PM
"Xlib: extension "XFree86-DRI" missing on display ":0.0"." zaps Linux - Games 9 05-14-2007 04:07 PM
"User" & "System" CPU load difference JJX Linux - General 3 06-06-2004 02:42 AM
"X-MS" cant open because "x-Multimedia System" cant access files at "smb&qu ponchy5 Linux - Networking 0 03-30-2004 12:18 AM
RH "null" beta system freezes right after printing "INIT" markus1982 Linux - Hardware 0 09-09-2002 04:31 PM


All times are GMT -5. The time now is 04:39 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration