I have written a windows service in VB.NET v5.0 on Windows XP SP3, which uses WinSCP v4.2.7 (Build 758) as a System.Diagnostics.Process to SFTP download some files locally and process them. This works perfectly on my workstation, but as soon as tried to move it onto the server it started failing.
The server I have put the service on is running Windows 2007 SP2, which apparently is known to stop any non-windows access to the system32 directory. I have installed WinSCP on the server and it can see the files ok, and my service is running through as expected apart from this one error message - "Could not find file 'C:\Windows\system32\log.xml'.". Support gave everyone full permissions to the directory, but it still could not create the file.
As an experiment I copied the file created on my desktop onto the server to see if it could write to an already existing file. Unfortunately it didn't write to the file, so it simply listed the files that had been found the last time it was run on my desktop rather than the files currently at the source (I'd requested a list).
I've tried giving a full path name for the XML log within the code. It still generated the file in the system32 directory, but did not appear to write to it, and consequently the service itself failed to process correctly.
I also tried removing the log request from the code, but it appeared to have no effect.
The protocol settings are the same on both my desktop and the server:
Session Protocol SSH-2
SSH Implementation OpenSSH_5.1p1 Debian-5ubuntu1
Encryption Algorithm AES
File Transfer Protocol SFTP-3
The scripting works correctly, but I've included some anyway just in case ...
Dim WinSCP As New Process
WinSCP.StartInfo.FileName = strWinSCP_Filename
WinSCP.StartInfo.Arguments = "/log=" & WINSCP_LOG_NAME WinSCP.StartInfo.UseShellExecute = False
WinSCP.StartInfo.RedirectStandardInput = True
WinSCP.StartInfo.RedirectStandardOutput = True
WinSCP.StartInfo.CreateNoWindow = True
boolStarted = WinSCP.Start()
WinSCP.StandardInput.WriteLine("option batch abort")
WinSCP.StandardInput.WriteLine("option confirm off")
strOpenCommand = "sftp://" & strUsername & ":" & strPassword & "@" & strHost & ":" & CStr(intPort) & " -hostkey=""" & strHostKey & """"
WinSCP.StandardInput.WriteLine("open " & strOpenCommand)
WinSCP.StandardInput.WriteLine("cd """ & strSFTPDir & """")
strOutput = WinSCP.StandardOutput.ReadToEnd()
The service is currently having to run off my desktop which is not ideal. Is there a way of working around this, running without the log, or relocating it?