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()