Posted: 2011-09-27 17:04
I have some very simple code running in a VB Application that calls WinSCP.com in order to download a file. On my development machine I default installed WinSCP, wrote the code and everything worked perfectly. I installed the same WinSCP the same way on the live machine for getting this data and the ExitCode is now being returned as 1 not the expected 0.
I added log file generation to the code - my machine works fine but the live machine doesn't generate a log file even though I have checked in my code that the WinSCP process is running. As per the FAQ's I put WinSCp in the path so it can be accessed from anywhere on the machine - still nothing.
I've tried setting up the security settings on everything I can find to All Access - still nothing.
I'm basically stumped as to what to look for or how to get more information from WinSCP to give me a clue whats going wrong here. Anybody got any ideas????
Here's a cut down version of the code - currently it's full of debug stuff that might just confuse things if I left it in (obviously all variables e.g. host, password, TargetFile etc. are valid at run time)
Dim SFTP_APP_LOCATION As String = "C:\Program Files\WinSCP\winscp.com"
Dim winscp As Process = New Process
winscp.StartInfo.FileName = SFTP_APP_LOCATION
winscp.StartInfo.Arguments = "/log=c:\Start_working_folder\App.log"
winscp.StartInfo.UseShellExecute = False
winscp.StartInfo.CreateNoWindow = True
winscp.StartInfo.RedirectStandardInput = True
' Use Process.GetProcessesByName("WinSCP")
winscp.StandardInput.WriteLine("open sftp://" & username & "@" & Host)
winscp.StandardInput.WriteLine(password) 'password characters not compatible with open statement
Dim commandline As String = "get /log/" & TargetFile & " " & LocalFile
Dim result as integer = winscp.ExitCode
Posted: 2011-09-29 16:56
In case anyone else comes across this post I thought I'd update it with how I dealt with the problem. Obviously the problem related to permissions but we don't have the expertise here to deal with that can of worms just now so I now create a script specific to the host prior to calling winSCP using a shell command e.g.
Shell("cmd.exe /k winSCP.com /script=" & ScriptFile......)
This seems to launch the cmd window with the same permissions as the calling app and everything works fine. Probably not the prettiest of solutions but it works.
Some things i noticed during my investigations:
1. Using the process technique I discovered that
winscp.StandardInput.WriteLine("open sftp://" & username & ":" & password & "@" & Host)
doesn't like passwords that have a "/" character in them. The password works fine when entered from command line prompt or from the GUI.
2. when using the "get" command it isn't very happy about spaces in the pathnames.
Anyway - thats all for now.
You can post new topics in this forum
And it's free!