Post a reply

Before posting, please read how to report bug or request support effectively.

Bug reports without an attached log file are usually useless.

Options
Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)

Options

Topic review

Angie

Re: Cannot write log to system32 directory, so request fails

oh, ok. Thanks for all your help. :)
martin

Re: Cannot write log to system32 directory, so request fails

OK, I see. So it has nothing to do with WinSCP. I do not know VB, so I cannot help you with this.
Angie

Re: Cannot write log to system32 directory, so request fails

Sorry for the delay in replying, I've been away a few days.

The statement throwing the 'Illegal characters in path' exception is ...

Dim log As XPathDocument = New XPathDocument("""" & strLogPath & WINSCP_LOG_NAME & """")

"""" & strLogPath & WINSCP_LOG_NAME & """"
is passed in as ...
"F:\CellMapImport\Log\winscp_log.xml"
(this directory exists already)
martin

Re: Cannot write log to system32 directory, so request fails

I belive you can image that this is not I wanted to know. I need to know what command does throw the exception.
Angie

Re: Cannot write log to system32 directory, so request fails

I've got a try...catch around the code posted previously, and when the exception is triggered the error message is written into the event log.


Catch ex As Exception
EventLog.WriteEntry(Me.ToString, "Error listing directory: " & ex.Message, EventLogEntryType.Error)

Finally
WinSCP.Dispose()
End Try
martin

Re: Cannot write log to system32 directory, so request fails

Where does the error come from?
Angie

Re: Cannot write log to system32 directory, so request fails

My apologies, it wasn't a very descriptive reply. I've just regenerated my problem, in order to remind myself exactly what it's doing. I must have made a mistake last time I tried to force a new location, as it worked correctly on my desktop this time.

I realised when it failed on the server again, that the file was being referenced again further down the code to read the contents, and that's why it was still failing. The log is now being generated in; and read from; the new location on the server.

Unfortunately, I am now getting an error "Illegal characters in path.". The path I'm passing in is "F:\CellMapImport\Log\winscp_log.xml" (including the quotes), which I get from the debug code directly above. The code is ...


Call WriteDebug(boolDebug, """" & strLogPath & WINSCP_LOG_NAME & """")
Dim log As XPathDocument = New XPathDocument("""" & strLogPath & WINSCP_LOG_NAME & """")
Dim ns As XmlNamespaceManager = New XmlNamespaceManager(New NameTable())
ns.AddNamespace("w", "https://winscp.net/schema/session/1.0")
Dim nav As XPathNavigator = log.CreateNavigator()

If intExitCode <> 0 Then
Call WriteDebug(boolDebug, "Error occured")

For Each message As XPathNavigator In nav.Select("//w:message", ns)
Call WriteDebug(boolDebug, message.Value)
Next

Else
Dim files As XPathNodeIterator = nav.Select("//w:file", ns)
ReDim strTempList(files.Count)

intLen = Len(Replace(strTemplate, "*", ""))

For Each file As XPathNavigator In files
strTempFile = file.SelectSingleNode("w:filename/@value", ns).Value
strFilenamePart = Right(strTempFile, intLen)
Call WriteDebug(boolDebug, "Filename Part = " & strFilenamePart)

If strFilenamePart = Replace(strTemplate, "*", "") Then
strTempList(intNoOfFiles) = strTempFile
intNoOfFiles += 1
End If
Next
Call WriteDebug(boolDebug, (String.Format("There are {0} files and subdirectories originally", files.Count)))

ReDim strList(intNoOfFiles)

For intCount = 0 To intNoOfFiles - 1
strList(intCount) = strTempList(intCount)
Next
Call WriteDebug(boolDebug, ("There are " & CStr(UBound(strList)) & " files matching template"))
End If

WinSCP.Close()
martin

Re: Cannot write log to system32 directory, so request fails

So what happens if you run WinSCP from command line like this?
winscp /log="c:\writtable_path\winscp.log"
Angie

Re: Cannot write log to system32 directory, so request fails

Thanks for the reply prikryl2,

I've no defined requirements for where the log is stored, I believe I'm only encountering problems because it's trying to write to a protected system directory. If it could be configurable, that could be useful though.

I did try it with double quotes, yes, and it still wasn't having it.
martin

Re: Cannot write log to system32 directory, so request fails

So where do you want the log to be actually stored to? When spevifyibg the full path, have you enclosed it to double-quotes?
Angie

Cannot write log to system32 directory, so request fails

I have a problem that my support team believe is due to permissions of the operating system used, which is blocking the XML log file being written to the system32 directory ...

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
Compression No
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 & """")
WinSCP.StandardInput.WriteLine("ls *")

WinSCP.StandardInput.Close()
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?

Cheers,
Angie