Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 09-09-2006, 02:21 AM   #1
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 in the str_echo.c in SERVER
		else if(strcmp(arg1,"pwd")==0) 
		 int pwd;
		else if(strcmp(arg1,"ls")==0)
		 int ls;
		Writen(sockfd, line, n);
can someone help me out plz..
Old 09-09-2006, 07:14 PM   #2
Registered: May 2006
Location: Argentina
Distribution: SuSE 10
Posts: 173

Rep: Reputation: 30
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, 08:08 PM   #3
LQ 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.

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


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 08:20 PM
Transfer file from slack to school server mustangfanatic01 Slackware 2 11-27-2005 02:58 AM
simple OS for a file server DaveSalt Linux - Newbie 3 02-26-2005 08:29 AM
Making a simple file server - which OS? DaveSalt Linux - Software 2 02-26-2005 07:19 AM
Setting up RHL9 as a simple file server daeus Linux - Software 3 01-27-2004 02:44 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:55 PM.

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