I have a simple function that I wish to perform in a .NET program. I am currently working in C# with .NET version 1.1, but any .NET language help would be useful. I want to be able to send a remote command to a UNIX or VxWorks computer form a Windows PC. From VxWorks to UNIX this would require only a single line of code - a call to the function "rcmd", as in this example that gets the time on the UNIX box:

int getHostDate
(
char *unixHost,
char *userId,
char *userPassword,
char *returnDate,
char returnErrorMsg[30],
int  outFormat	/* 0 = default 1 = numeric */
)

{
int rshdSockFd;
char userName[20];
char dateCmdStr[30];
char buf [BUFSIZE];
int nRead;


if (unixHost == NULL)
	{
	sprintf (returnErrorMsg,"Invalid host name\0");
	return (ERROR);
	}

if (outFormat == 1) {
	sprintf(dateCmdStr,
	       "date '+%%Y %%m %%d %%w %%H %%M %%S'");
	}
else	{
	sprintf(dateCmdStr,"date");
	}



   if (([b]rshdSockFd = rcmd (unixHost, RSH_PORT, userId, userPassword, dateCmdStr, 0)[/b]) == ERROR)
	{
	sprintf (returnErrorMsg,"Remote Command Failed\0");
	return (ERROR);
	}


if ((nRead = read(rshdSockFd, buf, BUFSIZE)) == ERROR)
	{
	sprintf (returnErrorMsg,"Read from Socket Failed\0");
	close (rshdSockFd);
	return (ERROR);
	}
else
	{
	buf [nRead - 1] = '\0';
	sprintf (returnDate,"%s", buf);
	close (rshdSockFd);
	return(nRead);
	}
}

I have searched the web to see what others do, and the usual answer is to write a new server on the UNIX side. This seems like severe overkill, as the ability to receive remote commands already exists in UNIX, as evidenced by the working code above. This action can be accomplished manually by simply bringing up a telnet window and typing in the appropriate commands. Is it really so difficult to do in .NET that it is better to change the UNIX server itself (a suggestion I wouldn't even think of making)?

Thanks,
Dale

>>This action can be accomplished manually by simply bringing up a telnet window and typing in the appropriate commands
When you bring up that telenet program doesn't it require you to log into the *nix box before you can do anything? Yes, then at that point there is a server program running on the *nix and your telenet session is nothing more than another terminal type to the *nix login shell. I don't think that is the same type session that you have in mind for your C# program.

>>This action can be accomplished manually by simply bringing up a telnet window and typing in the appropriate commands
When you bring up that telenet program doesn't it require you to log into the *nix box before you can do anything? Yes, then at that point there is a server program running on the *nix and your telenet session is nothing more than another terminal type to the *nix login shell. I don't think that is the same type session that you have in mind for your C# program.

Thanks for the quick response. I admit I am not enough of an expert to know if the 'rcmd' function utilizes telnet protocol, but if you look at the function in the code I posted, it contains parameters for the user ID and password so, yes, in a sense, it looks like it is logging you in every time it is called. In the same way, you can log in from any UNIX station to any other UNIX station that you have an account on, use FTP protocol to transfer files, or mount a disk from another machine if it is configured to allow this. I had thought that .NET was intended to expand interoperability across platforms, so I hoped it would have some functionality to handle these types of operations. I understand that .NET 2.0 and above does support FTP protocol for moving files. I don't know if Telnet protocol is ever going to be supported for remote commands.

I definitely don't want to write my own telnet protocol code. Hyperterminal is loaded on my PC, but it does not seem to support scripting or a way to support return values to a program. There may another third party program I can use, but I haven't found it yet.

Thanks again,
Dale

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.