Automating ftp command line application redirecting I/O in .Net

Posted by SoMoS on Stack Overflow See other posts from Stack Overflow or by SoMoS
Published on 2010-03-18T14:29:37Z Indexed on 2010/03/18 14:31 UTC
Read the original article Hit count: 491

Filed under:
|
|
|
|

Hello,

I'm trying to automate the ftp client that Windows includes redirecting the I/O from the process. What I'm doing is starting the process from my application and trying to read what the client prints on the screen and sending my commands to it.

The problem is that I can not read almost any data sent by the ftp client. Some data is present but most data is not read. That's the code I have until now.

Public Sub Start()
    process = New Diagnostics.Process()
    process.StartInfo.FileName = "ftp.exe" #'' The command is on the path
    process.StartInfo.CreateNoWindow = True
    process.StartInfo.RedirectStandardInput = True
    process.StartInfo.RedirectStandardOutput = True
    process.StartInfo.UseShellExecute = False
    process.Start()

    process.StandardInput.AutoFlush = True
    process.BeginOutputReadLine()
End Sub

#'' takes data from the stdout
Private Sub process_OutputDataReceived(ByVal sender As Object, ByVal e As System.Diagnostics.DataReceivedEventArgs) Handles process.OutputDataReceived
    #'' At this moment here there is code to show the stdout at a textbox
End Sub

#'' sends data to stdin
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
    process.StandardInput.WriteLine(Me.TextEdit1.Text)
End Sub

Now when I execute this for example and send ? I just get the first line (and I should get a lot more). Or when I send the open command I should receive an A but nothing is received. Any ideas?

Another question is ... when a console applications writes on the screen it always does that by writing at the stdout or the stderr isn't it?

© Stack Overflow or respective owner

Related posts about shell

Related posts about .NET