VB.net code issue!
Ok... so i tried it a million ways and it just doesnt want to work.
I created a saved session "OD" in winscp. Also set the local and remote directories too. Then tested through the GUI and it worked.
So then I created a batch file (pushit.bat) and it contains: "C:\FTPTEST\winscp422.exe" /console /script=C:\FTPTEST\pushfiles_Script.txt
pushfiles_Script.txt contains:
option batch on
option confirm off
open OD
put -speed=300 *
close
exit
If I run the batch file manually, it works... so I know I have a valid test case here..
So here's my code... First started with just calling the .bat instead of dealing with the standardinput and adding cmds...
I ALSO tried calling the exe too.
ALSO through ARGS .. OneComma is a string const for a single Comma Char. I can even say I did the script syntax of doubling and tripling them according to the site... that didnt work neither.
Also... if I go to Start > Run and execute: C:\FTPTEST\winscp422.exe /console /command "option batch on" "open OD" "put *" "exit"
that Works too...
So what's wrong with .net kicking off this process?! It never completes and yes at one point i removed the wait time to unlimited to makes sure my 20seconds max was the issue either...
Help :-D
I created a saved session "OD" in winscp. Also set the local and remote directories too. Then tested through the GUI and it worked.
So then I created a batch file (pushit.bat) and it contains: "C:\FTPTEST\winscp422.exe" /console /script=C:\FTPTEST\pushfiles_Script.txt
pushfiles_Script.txt contains:
option batch on
option confirm off
open OD
put -speed=300 *
close
exit
If I run the batch file manually, it works... so I know I have a valid test case here..
So here's my code... First started with just calling the .bat instead of dealing with the standardinput and adding cmds...
Private Function winscpCaller() As Boolean Dim winscp As Process = New Process() Dim results As Boolean = False Try winscp.StartInfo.FileName = C:\FTPTEST\pushfiles_Script.bat" winscp.StartInfo.UseShellExecute = False winscp.StartInfo.RedirectStandardInput = True winscp.StartInfo.RedirectStandardOutput = True winscp.StartInfo.CreateNoWindow = True winscp.Start() ' Wait until WinSCP finishes winscp.WaitForExit(20000) '= 20seconds ' Success (0) or error? If winscp.Has_Exited Then ' winscp.ExitCode <> 0 Then '(the forum blocks s E x) results = True Else results = False End If Catch ex As Exception WriteToErrorLog("error- " + ex.Message) winscp.Kill() winscp.Close() winscp.Dispose() Return False Exit Function Finally If results = False Then WriteToErrorLog("Process Killed") winscp.Kill() winscp.Close() winscp.Dispose() Else WriteToErrorLog("Completed") winscp.Close() winscp.Dispose() End If End Try Return results End Function
I ALSO tried calling the exe too.
Private Function winscpCaller(ByVal ProcessPathPlusName) As Boolean Dim winscp As Process = New Process() Dim results As Boolean = False Try ' Run hidden WinSCP process winscp.StartInfo.FileName = ProcessPathPlusName '= C:\FTPTEST\winscp422.exe (path + exe name) winscp.StartInfo.UseShellExecute = False winscp.StartInfo.RedirectStandardInput = True winscp.StartInfo.CreateNoWindow = true winscp.Start() ' Feed in the scripting commands winscp.StandardInput.WriteLine("option batch on") winscp.StandardInput.WriteLine("option confirm off") winscp.StandardInput.WriteLine("open OD") winscp.StandardInput.WriteLine("put *") winscp.StandardInput.WriteLine("close") winscp.StandardInput.WriteLine("exit") winscp.StandardInput.Close() ' Wait until WinSCP finishes winscp.WaitForExit(20000) '= 20seconds max wait ' Success (0) or error? If winscp.Has_Exited Then ' winscp.ExitCode <> 0 Then '(the forum blocks s E x) results = True WriteToErrorLog("process has exited normally") Else results = False WriteToErrorLog("process has not exited normally") End If Catch ex As Exception WriteToErrorLog("error- " + ex.Message) winscp.Kill() winscp.Close() winscp.Dispose() Return False Exit Function Finally If results = False Then WriteToErrorLog("Process Killed") winscp.Kill() winscp.Close() winscp.Dispose() Else WriteToErrorLog("Completed") winscp.Close() winscp.Dispose() End If End Try Return results End Function
ALSO through ARGS .. OneComma is a string const for a single Comma Char. I can even say I did the script syntax of doubling and tripling them according to the site... that didnt work neither.
winscp.StartInfo.FileName = ProcessPathPlusName '= C:\FTPTEST\winscp422.exe (path + exe name) winscp.StartInfo.Arguments = "/console /command " & _ Onecomma & "option batch on" & Onecomma & " " & _ Onecomma & "open OracleDataFeed" & Onecomma & " " & _ Onecomma & "put *" & Onecomma & " " & _ Onecomma & "exit" & Onecomma winscp.StartInfo.UseShellExecute = False winscp.StartInfo.RedirectStandardInput = True winscp.StartInfo.CreateNoWindow = true winscp.Start()
Also... if I go to Start > Run and execute: C:\FTPTEST\winscp422.exe /console /command "option batch on" "open OD" "put *" "exit"
that Works too...
So what's wrong with .net kicking off this process?! It never completes and yes at one point i removed the wait time to unlimited to makes sure my 20seconds max was the issue either...
Help :-D