Pass input parameter to a process using Process.StandardInput.WriteLn
Posted on 2003-03-29
I have struggled for days with this one.
I have written a vb code to run a bat file to start an ftp process, the problem is that I need to input the user name, and password and then after that I need to transfer a file (using put command).
When I execute the ftp command as the following I have no problem
ftp -s:Filename.txt 10.10.10.245
where FileName.txt contains the command I wish to execute right after FTP starts ( including the authentication).
This solution will not work for me since the file name that I am transferring varies from within the program and I cannot hardcode it into the text file.
The System.Diagnostics.process and System.Diagnostics.ProcessStartInfo allow to write input to the process , and this is what I tried in the following code but it was unsucessfull.
Dim pStart As New System.Diagnostics.ProcessStartInfo()
pStart.FileName = Directory.GetCurrentDirectory & "\ftpLog.bat"
pStart.RedirectStandardInput = True
pStart.UseShellExecute = False
Dim ftpProcess As New Process()
ftpProcess.StartInfo = pStart
Dim stWriter As StreamWriter()
ftpProcess.StandardInput.AutoFlush = True
ftpProcess.StandardInput.WriteLine("mput c:\tempdir\" + strFileName)