473,763 Members | 1,377 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 3672
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
7477
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
2263
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
1818
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
1677
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
1277
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
3022
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
6235
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
2187
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
16148
by: SeC | last post by:
Hi. Is there any way to detect if application is being killed by 'End Process' via Task Manager ?
0
9563
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9998
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...
1
9938
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8822
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7366
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
5270
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5406
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3523
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2793
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.