LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-09-2006, 03:21 AM   #1
sachitha
Member
 
Registered: Aug 2003
Location: Sri Lanka
Distribution: Redhat 9.0
Posts: 104

Rep: Reputation: 15
a simple file transfer server..


i'm trying to create a simple file transfer program using C sockets..
i need to print the server's present working directory(PWD) in the client's prompt, when client input the word "pwd"
i have written the following coding for that.. but the pwd is printed in the server's prompt , instead of the client's prompt

Code:
//code in the str_echo.c in SERVER
.......
.......
		else if(strcmp(arg1,"pwd")==0) 
		{
		 int pwd;
		 pwd=system("pwd");	
		 snprintf(line,sizeof(line),(char*)pwd);	
		}
		else if(strcmp(arg1,"ls")==0)
		{
		 int ls;
		 ls=system("ls");
		 snprintf(line,sizeof(line),(char*)ls);				
		}
.........
......
		n=strlen(line);
		Writen(sockfd, line, n);
can someone help me out plz..
 
Old 09-09-2006, 08:14 PM   #2
demon_vox
Member
 
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
Hi,
the function Writeln does not exist on my man pages... maybe you wrote it and the error is in it. Or it could be that sockfd is not what you want (could you have put the stdout in it?).

And another thing (not related to the networking part): system does not return a string. That means that the output is going to stdout and you are missing it. Which is probably what you are seeing on the screen. If you want to get the output, use popen.

Most likely the networking part is just ok and the problem is the one I described in the paragraph above, but I cant tell for sure since I dont know the code.

Hope this is useful!
 
Old 09-09-2006, 09:08 PM   #3
paulsm4
Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Getting back to your original question:

Demon_vox is absolutely correct. The server is printing "pwd" to the server's command-line because you're having the server run the program "pwd" ... which outputs to stdout ... the *SERVER'S* "stdout". Duh.

Opening a pipe to the "pwd" command is one solution.

Using "popen()/read()/pclose ()" (which, under the covers, opens the pipes for you) is an equivalent - and much easier to code - solution.

Simply calling "getcwd()", however, is probably the easiest solution.

Quote:
man 3 getcwd
man 3 popen
'Hope that helps .. PSM
 
  


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
[most secure, open source, client/server file transfer program] Synesthesia Linux - Software 5 11-28-2005 09:20 PM
Transfer file from slack to school server mustangfanatic01 Slackware 2 11-27-2005 03:58 AM
simple OS for a file server DaveSalt Linux - Newbie 3 02-26-2005 09:29 AM
Making a simple file server - which OS? DaveSalt Linux - Software 2 02-26-2005 08:19 AM
Setting up RHL9 as a simple file server daeus Linux - Software 3 01-27-2004 03:44 AM


All times are GMT -5. The time now is 11:02 PM.

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