By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,563 Members | 1,066 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,563 IT Pros & Developers. It's quick & easy.

Execute Unix command using C#

P: n/a
Hi,
I am trying to develop a C# application that will run
on Windows that will do the following
* Select file name to process
* FTP the file to a UNIX server
* Process this file on UNIX using a program on UNIX
"./pgmname -options Infilename > OutputFilename"
* FTP the output of this program back to Windows
* Process the resultant file and create output report file

I am not sure about how to execute the Unix command and
wait for the execution to be complete... Could someone
help me out here?

For the FTP, I plan to use the following... Is this ok?
Ftp ftp = new Ftp();
ftp.Connect (hostname);
ftp.Login (username, password);
// set transfer type to binary
ftp.SetTransferType (FtpTransferType.Binary);
// download file and display number of bytes transferred
long bytes = ftp.GetFile (remotePath, localPath);
Console.WriteLine ("Transfered {0} bytes.", bytes);
// disconnect
ftp.Disconnect();
Thanks
- Joseph
Nov 15 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Joseph, how would you do this if you weren't programming it?

--
Greg Ewing [MVP]
http://www.citidc.com

"Joseph" <jo**********@nospam.com> wrote in message
news:2b****************************@phx.gbl...
Hi,
I am trying to develop a C# application that will run
on Windows that will do the following
* Select file name to process
* FTP the file to a UNIX server
* Process this file on UNIX using a program on UNIX
"./pgmname -options Infilename > OutputFilename"
* FTP the output of this program back to Windows
* Process the resultant file and create output report file

I am not sure about how to execute the Unix command and
wait for the execution to be complete... Could someone
help me out here?

For the FTP, I plan to use the following... Is this ok?
Ftp ftp = new Ftp();
ftp.Connect (hostname);
ftp.Login (username, password);
// set transfer type to binary
ftp.SetTransferType (FtpTransferType.Binary);
// download file and display number of bytes transferred
long bytes = ftp.GetFile (remotePath, localPath);
Console.WriteLine ("Transfered {0} bytes.", bytes);
// disconnect
ftp.Disconnect();
Thanks
- Joseph

Nov 15 '05 #2

P: n/a
there is a few ways to execute remote commands on a unix machine, since you
are using ftp then I figure its a fairly unsecure box, so telnet or some
other remote command execution technology. You could use SSH for a little
added security, im sure there is alreayd some sort of telnet or SSH API on
..net or at least sample code, telnet would be extremely easy to pull off.
Alternatively you could make a webpage on the unix system that executes that
program and call that webpage from c#.
"Joseph" <jo**********@nospam.com> wrote in message
news:2b****************************@phx.gbl...
Hi,
I am trying to develop a C# application that will run
on Windows that will do the following
* Select file name to process
* FTP the file to a UNIX server
* Process this file on UNIX using a program on UNIX
"./pgmname -options Infilename > OutputFilename"
* FTP the output of this program back to Windows
* Process the resultant file and create output report file

I am not sure about how to execute the Unix command and
wait for the execution to be complete... Could someone
help me out here?

For the FTP, I plan to use the following... Is this ok?
Ftp ftp = new Ftp();
ftp.Connect (hostname);
ftp.Login (username, password);
// set transfer type to binary
ftp.SetTransferType (FtpTransferType.Binary);
// download file and display number of bytes transferred
long bytes = ftp.GetFile (remotePath, localPath);
Console.WriteLine ("Transfered {0} bytes.", bytes);
// disconnect
ftp.Disconnect();
Thanks
- Joseph

Nov 15 '05 #3

P: n/a
Greg,
Currently, we do a manual process where we..
1. FTP the file to be processed to the UNIX machine
2. Execute the statement on the UNIX machine (using Telnet)
"./pgmname -options Infilename > OutputFilename"
3. FTP the outputfile back to local machine
4. Process the resultant file and create output report file

- Joseph
-----Original Message-----
Joseph, how would you do this if you weren't programming it?
--
Greg Ewing [MVP]
http://www.citidc.com

"Joseph" <jo**********@nospam.com> wrote in message
news:2b****************************@phx.gbl...
Hi,
I am trying to develop a C# application that will run on Windows that will do the following
* Select file name to process
* FTP the file to a UNIX server
* Process this file on UNIX using a program on UNIX
"./pgmname -options Infilename > OutputFilename"
* FTP the output of this program back to Windows
* Process the resultant file and create output report file
I am not sure about how to execute the Unix command and
wait for the execution to be complete... Could someone
help me out here?

For the FTP, I plan to use the following... Is this ok?
Ftp ftp = new Ftp();
ftp.Connect (hostname);
ftp.Login (username, password);
// set transfer type to binary
ftp.SetTransferType (FtpTransferType.Binary);
// download file and display number of bytes transferred
long bytes = ftp.GetFile (remotePath, localPath);
Console.WriteLine ("Transfered {0} bytes.", bytes);
// disconnect
ftp.Disconnect();
Thanks
- Joseph

.

Nov 15 '05 #4

P: n/a
Joseph, so what you need is a telnet client for C# right? You have a couple
of options, write your own, buy one, or download a free one. Here's a link
to some samples to get you started.

http://www.gotdotnet.com/community/u...x?query=telnet

--
Greg Ewing [MVP]
http://www.citidc.com
"Joseph" <jo**********@nospam.com> wrote in message
news:05****************************@phx.gbl...
Greg,
Currently, we do a manual process where we..
1. FTP the file to be processed to the UNIX machine
2. Execute the statement on the UNIX machine (using Telnet)
"./pgmname -options Infilename > OutputFilename"
3. FTP the outputfile back to local machine
4. Process the resultant file and create output report file

- Joseph
-----Original Message-----
Joseph, how would you do this if you weren't programming

it?

--
Greg Ewing [MVP]
http://www.citidc.com

"Joseph" <jo**********@nospam.com> wrote in message
news:2b****************************@phx.gbl...
Hi,
I am trying to develop a C# application that will run on Windows that will do the following
* Select file name to process
* FTP the file to a UNIX server
* Process this file on UNIX using a program on UNIX
"./pgmname -options Infilename > OutputFilename"
* FTP the output of this program back to Windows
* Process the resultant file and create output report file
I am not sure about how to execute the Unix command and
wait for the execution to be complete... Could someone
help me out here?

For the FTP, I plan to use the following... Is this ok?
Ftp ftp = new Ftp();
ftp.Connect (hostname);
ftp.Login (username, password);
// set transfer type to binary
ftp.SetTransferType (FtpTransferType.Binary);
// download file and display number of bytes transferred
long bytes = ftp.GetFile (remotePath, localPath);
Console.WriteLine ("Transfered {0} bytes.", bytes);
// disconnect
ftp.Disconnect();
Thanks
- Joseph

.

Nov 15 '05 #5

P: n/a
Oh wow... I didn't realize this was gonna be so
complicated - I guess I was hoping for something simple
like the way FTP is implemented... I guess I will have to
think up some other way...
Thanks for your help though Greg - and most of all, thank
you for the link! It has a LOT of useful info!

- Joseph
-----Original Message-----
Joseph, so what you need is a telnet client for C# right? You have a coupleof options, write your own, buy one, or download a free one. Here's a linkto some samples to get you started.

http://www.gotdotnet.com/community/u...les/Default.as px?query=telnet
--
Greg Ewing [MVP]
http://www.citidc.com
"Joseph" <jo**********@nospam.com> wrote in message
news:05****************************@phx.gbl...
Greg,
Currently, we do a manual process where we..
1. FTP the file to be processed to the UNIX machine
2. Execute the statement on the UNIX machine (using Telnet) "./pgmname -options Infilename > OutputFilename"
3. FTP the outputfile back to local machine
4. Process the resultant file and create output report file
- Joseph
>-----Original Message-----
>Joseph, how would you do this if you weren't programming
it?
>
>--
>Greg Ewing [MVP]
>http://www.citidc.com
>
>"Joseph" <jo**********@nospam.com> wrote in message
>news:2b****************************@phx.gbl...
>> Hi,
>> I am trying to develop a C# application that
will run
>> on Windows that will do the following
>> * Select file name to process
>> * FTP the file to a UNIX server
>> * Process this file on UNIX using a program on UNIX
>> "./pgmname -options Infilename > OutputFilename"
>> * FTP the output of this program back to Windows
>> * Process the resultant file and create output
report file
>>
>> I am not sure about how to execute the Unix command

and >> wait for the execution to be complete... Could someone >> help me out here?
>>
>> For the FTP, I plan to use the following... Is this ok? >> Ftp ftp = new Ftp();
>> ftp.Connect (hostname);
>> ftp.Login (username, password);
>> // set transfer type to binary
>> ftp.SetTransferType (FtpTransferType.Binary);
>> // download file and display number of bytes transferred >> long bytes = ftp.GetFile (remotePath, localPath);
>> Console.WriteLine ("Transfered {0} bytes.", bytes);
>> // disconnect
>> ftp.Disconnect();
>>
>>
>> Thanks
>> - Joseph
>
>
>.
>

.

Nov 15 '05 #6

P: n/a
I just had a different idea.
Why not write a little shell script on the unix machine that monitors when
that file you are ftping is changed and then it executes the process?
"Joseph" <jo**********@nospam.com> wrote in message
news:07****************************@phx.gbl...
Oh wow... I didn't realize this was gonna be so
complicated - I guess I was hoping for something simple
like the way FTP is implemented... I guess I will have to
think up some other way...
Thanks for your help though Greg - and most of all, thank
you for the link! It has a LOT of useful info!

- Joseph
-----Original Message-----
Joseph, so what you need is a telnet client for C#

right? You have a couple
of options, write your own, buy one, or download a free

one. Here's a link
to some samples to get you started.

http://www.gotdotnet.com/community/u...les/Default.as

px?query=telnet

--
Greg Ewing [MVP]
http://www.citidc.com
"Joseph" <jo**********@nospam.com> wrote in message
news:05****************************@phx.gbl...
Greg,
Currently, we do a manual process where we..
1. FTP the file to be processed to the UNIX machine
2. Execute the statement on the UNIX machine (using Telnet) "./pgmname -options Infilename > OutputFilename"
3. FTP the outputfile back to local machine
4. Process the resultant file and create output report file
- Joseph

>-----Original Message-----
>Joseph, how would you do this if you weren't programming it?
>
>--
>Greg Ewing [MVP]
>http://www.citidc.com
>
>"Joseph" <jo**********@nospam.com> wrote in message
>news:2b****************************@phx.gbl...
>> Hi,
>> I am trying to develop a C# application that will run
>> on Windows that will do the following
>> * Select file name to process
>> * FTP the file to a UNIX server
>> * Process this file on UNIX using a program on UNIX
>> "./pgmname -options Infilename > OutputFilename"
>> * FTP the output of this program back to Windows
>> * Process the resultant file and create output report file
>>
>> I am not sure about how to execute the Unix command and >> wait for the execution to be complete... Could someone >> help me out here?
>>
>> For the FTP, I plan to use the following... Is this ok? >> Ftp ftp = new Ftp();
>> ftp.Connect (hostname);
>> ftp.Login (username, password);
>> // set transfer type to binary
>> ftp.SetTransferType (FtpTransferType.Binary);
>> // download file and display number of bytes transferred >> long bytes = ftp.GetFile (remotePath, localPath);
>> Console.WriteLine ("Transfered {0} bytes.", bytes);
>> // disconnect
>> ftp.Disconnect();
>>
>>
>> Thanks
>> - Joseph
>
>
>.
>

.

Nov 15 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.