473,625 Members | 3,253 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Process question

ask
Hi NG

I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process
and pipe command streams into it. But I cant make it work, it always stalls
when I try to read the output:

/// code 1
Process ftpProcess = new Process();

ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;

ftpProcess.Star t();

string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();

//... further ftp action - but I never get this far....

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Wait ForExit();
///////////

I also tried:

/// code2
char [] output = new char [1000];
string all = "";

Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx

ps. And yes - I did connect manually by the command prompt so it should
work.
Nov 15 '05 #1
5 3658
The reason it is hanging is that it is probably waiting for input of
some kind (username probably).

However, one has to ask, why not use a third party library to FTP, or
the WinInet functions for FTP through the P/Invoke layer? It would be a
much cleaner solution and give you much more control over the process.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- nick(dot)paldin o=at=exisconsul ting<dot>com

"ask" <a@creepREM.d k> wrote in message
news:3f******** *************@n ews.dk.uu.net.. .
Hi NG

I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process and pipe command streams into it. But I cant make it work, it always stalls when I try to read the output:

/// code 1
Process ftpProcess = new Process();

ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;

ftpProcess.Star t();

string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();

//... further ftp action - but I never get this far....

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Wait ForExit();
///////////

I also tried:

/// code2
char [] output = new char [1000];
string all = "";

Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx

ps. And yes - I did connect manually by the command prompt so it should
work.

Nov 15 '05 #2
Hi,

I've tried this with the FTP command myself using VBScripting, but never got
it to work, so I don't think it's C# problem, but might be something with
the FTP tool. What I ended up doing was to write a script that generated an
FTP script, and then used the -s option of the ftp tools to read that script
instead.
Arild

"ask" <a@creepREM.d k> wrote in message
news:3f******** *************@n ews.dk.uu.net.. .
Hi NG

I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process and pipe command streams into it. But I cant make it work, it always stalls when I try to read the output:

/// code 1
Process ftpProcess = new Process();

ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;

ftpProcess.Star t();

string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();

//... further ftp action - but I never get this far....

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Wait ForExit();
///////////

I also tried:

/// code2
char [] output = new char [1000];
string all = "";

Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx

ps. And yes - I did connect manually by the command prompt so it should
work.

Nov 15 '05 #3
Hi,

I've tried this with the FTP command myself using VBScripting, but never got
it to work, so I don't think it's C# problem, but might be something with
the FTP tool. What I ended up doing was to write a script that generated an
FTP script, and then used the -s option of the ftp tools to read that script
instead.
Arild

"ask" <a@creepREM.d k> wrote in message
news:3f******** *************@n ews.dk.uu.net.. .
Hi NG

I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process and pipe command streams into it. But I cant make it work, it always stalls when I try to read the output:

/// code 1
Process ftpProcess = new Process();

ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;

ftpProcess.Star t();

string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();

//... further ftp action - but I never get this far....

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Wait ForExit();
///////////

I also tried:

/// code2
char [] output = new char [1000];
string all = "";

Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx

ps. And yes - I did connect manually by the command prompt so it should
work.

Nov 15 '05 #4
This is a classic you will see if you use Process class incorrectly.
You can read the document about Process class to understand why this
happens.
Always read the document :)
In our next release, you will be able to get the output asynchrously.

Gang Peng
[MS]

"ask" <a@creepREM.d k> wrote in message
news:3f******** *************@n ews.dk.uu.net.. .
Hi NG

I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process and pipe command streams into it. But I cant make it work, it always stalls when I try to read the output:

/// code 1
Process ftpProcess = new Process();

ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;

ftpProcess.Star t();

string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();

//... further ftp action - but I never get this far....

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Wait ForExit();
///////////

I also tried:

/// code2
char [] output = new char [1000];
string all = "";

Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx

ps. And yes - I did connect manually by the command prompt so it should
work.

Nov 15 '05 #5
This is a classic you will see if you use Process class incorrectly.
You can read the document about Process class to understand why this
happens.
Always read the document :)
In our next release, you will be able to get the output asynchrously.

Gang Peng
[MS]

"ask" <a@creepREM.d k> wrote in message
news:3f******** *************@n ews.dk.uu.net.. .
Hi NG

I'm a bit new to programming c# and have a question regarding ftp by the
command prompt. As far as I can see it should be possible to start a process and pipe command streams into it. But I cant make it work, it always stalls when I try to read the output:

/// code 1
Process ftpProcess = new Process();

ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;

ftpProcess.Star t();

string output = ftpProcess.Stan dardOutput.Read ToEnd();
string error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("ftp localhost");
ftpProcess.Stan dardInput.Write Line();

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line();

//... further ftp action - but I never get this far....

output = ftpProcess.Stan dardOutput.Read ToEnd();
error = ftpProcess.Stan dardError.ReadT oEnd();

ftpProcess.Wait ForExit();
///////////

I also tried:

/// code2
char [] output = new char [1000];
string all = "";

Process ftpProcess = new Process();
ftpProcess.Star tInfo.FileName = "cmd";
ftpProcess.Star tInfo.CreateNoW indow = true;
ftpProcess.Star tInfo.RedirectS tandardInput = true;
ftpProcess.Star tInfo.RedirectS tandardOutput = true;
ftpProcess.Star tInfo.UseShellE xecute = false;
ftpProcess.Star t();
int i = ftpProcess.Stan dardOutput.Read (output, 0, 1000);
ftpProcess.Stan dardInput.Write Line("ftp localhost");
i = ftpProcess.Stan dardOutput.Read (output, i, 1000-i);
ftpProcess.Stan dardInput.Write Line("username" );
ftpProcess.Stan dardInput.Write Line("password" );
ftpProcess.Stan dardInput.Write Line("mkdir test");
ftpProcess.Stan dardInput.Write Line("ls");
ftpProcess.Stan dardInput.Write Line("bye");
all = ftpProcess.Stan dardOutput.Read ToEnd();
thanx

ps. And yes - I did connect manually by the command prompt so it should
work.

Nov 15 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
7452
by: Michael J. Moore | last post by:
Is it the listener process, or some other Oracle process. Also, on a UNIX system, when you do "ps -ef" to see your processes, the PPID points back to a process named "init". Why does the PPID not point to some other process like, for example, the listener, or PMON, or whoever spawned it. thanks, Mike
2
2258
by: mwazir | last post by:
Hi all, I have reposted this question from dotnet.general as I have been advised that this is a more appropriate forum for this question. Apologies for the repost. I have a process thats starts in my application and only terminates when my application is terminated. I want to write the output and the errors of this process to a seperate log file. In order to do this, I spawned two threads.
1
1808
by: Doug Wyatt | last post by:
So I'll preface this with the fact that I'm a UNIX developer by training and have just recently gotten in to C# development on Windows. I'm basically running in to a problem whereby I suspect something to do with process groups or threads and closeOnExec semantics (to speak in POSIX terms) is causing me a problem. I've got a windows service (let's call it "myService") that, among other things, does : onStart creates a TcpListener on a...
6
493
by: A | last post by:
Hi all, This is sort of a newbie question. I have a method that creates a process which in turn installs MSDE. Basically, after I start the process I need to wait until it is complete and then reboot the machine. Problem is that I am unsure of knowing exactly when the process has completed since any code placed after the proc.Start() method executes asynchronously. I am not certain if what I need to do is implement some sort of...
2
1673
by: ca___t | last post by:
Hi there : I want to start a consoneApplication using process.start method at web application server side.I have a question at this.Why the consoneApplication's process is start but not run consoneApplication's code.But if I run the WebForm1.cs's code at a WinApplication project.it can start the consoneApplication's process and run the consoneApplication's code. How to solve this question?
3
1269
by: Nikolay Petrov | last post by:
I have a class which starts a process and redirects it's output and input. My class have a method which starts the process and another which stops it. How can I check if the process have been already started, so I don't try to start it again, and how to check if the process is not running so i don't try to stop again? code: Public Class ProcEx Private p As Process Public Sub StartProcess()
22
3004
by: Zen | last post by:
Hi, My production machine has 2G of memory, when aspnet_wp.exe goes up to about ~1.2G of memory usage, I start get out-of-memory exception. Other processes don't use as much memory and I added all the peak memory usage of all the processes (including aspnet_wp.exe), it goes up to no more than 1.5. How is that possible? Would anyone know please help? thanks!
2
6224
by: tony.newsgrps | last post by:
Hi there, I'm trying to understand the impact of killing a process that owns a system mutex (used to ensure there is only 1 instance of my program running) Here is my code pretty much: try { mutex=new System.Threading.Mutex( true, mutexName, out createdNew)
10
2180
by: Susan | last post by:
I have a process that takes a while to run so I have it running asynchronously so that the user can continue working. My question is that I want to killl the process if the user changes the search parameters before the callback method is called. Any ideas of how to do this or if it even matters? I did not know if calling the asynch process a new time kills the previous one or not. Thank you for your help. Susan
9
16101
by: SeC | last post by:
Hi. Is there any way to detect if application is being killed by 'End Process' via Task Manager ?
0
8189
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8635
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8497
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6118
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4193
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2621
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1803
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1500
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.