VB.net code issue!

Advertisement

GuessingGame
Guest

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...
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

Reply with quote

Advertisement

GuessingGame
Guest

Re: VB.net code issue!

No calling a .bat works fine.

However... you solved it. I wanted to just call the .exe directly... However, now following your advice and calling the .com it worked. (kinda) ... So I created a stored session and if i run the .com and in the cmd prompt type open mysession_name, it connects etc and basically finds the stored session. However reviewing the output log thats produced from my .net app, it says session not found and never connects to the remote server. I reviewed the session name in code to confirm i spelled everything right. Thoughts?

I am creating a windows service which uses a file watcher to immediately push a file to the ftp location. Could the service running as the OS admin not able to see my stored session I created on my windows admin user account?? I would think this is odd but worth mentioning to see it sparks any additional thoughts :D

Thanks for the help so far!

Reply with quote

Advertisement

You can post new topics in this forum