Topic "Script works on Win 7 but Not Server 2003"

Author Message
CBW

Guest


I have this script working, as was posted in the guides section, to check if a file exists. It works fantastically on Windows 7, but on server 2003 it will never return if the file is found. Any ideas?

Here is the script:
Code:

var FILEPATH = "../zfinance/TSA";
 
// Session to connect to
var SESSION = "someplace@somewhere.com";
 
// Path to winscp.com
var WINSCP = "c:\\program files\\winscp\\winscp.com";
 
var filesys = WScript.CreateObject("Scripting.FileSystemObject");
var shell = WScript.CreateObject("WScript.Shell");
 
var logfilepath = filesys.GetSpecialFolder(2) + "\\" + filesys.GetTempName() + ".xml";
var p = FILEPATH.lastIndexOf('/');
var path = FILEPATH.substring(0, p);
var filename = FILEPATH.substring(p + 1);
var exec;
 
// run winscp to check for file existence
exec = shell.Exec("\"" + WINSCP + "\" /log=\"" + logfilepath + "\"");
exec.StdIn.Write(
    "option batch abort\n" +
    "open \"" + SESSION + "\"\n" +
    "ls \"" + path + "\"\n" +
    "exit\n");
// wait until the script finishes
while (exec.Status == 0)
{
    WScript.Sleep(100);
    WScript.Echo(exec.StdOut.ReadAll());
}
if (exec.ExitCode != 0)
{
    WScript.Echo("Error checking for file existence");
    WScript.Quit(1);
}
// look for log file
var logfile = filesys.GetFile(logfilepath);
if (logfile == null)
{
    WScript.Echo("Cannot find log file");
    WScript.Quit(1);
}
// parse XML log file
var doc = new ActiveXObject("MSXML2.DOMDocument.6.0");
doc.async = false;
doc.load(logfilepath);
doc.setProperty("SelectionNamespaces",
    "xmlns:w='http://winscp.net/schema/session/1.0'");
 
doc.setProperty("SelectionLanguage", "XPath");             
var nodes = doc.selectNodes("//w:file/w:filename[starts-with(@value, '" + filename + "')]");
if (nodes.length > 0)
{
    WScript.Echo("File found");
    // signalize file existence to calling process;
    // you can also continue with processing (e.g. downloading the file)
    // directly from the script here
    WScript.Quit(0);
}
else
{
    WScript.Echo("File not found");        //this is always the result on jack.ser
    WScript.Quit(1);
}
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24556
Location: Prague, Czechia
1) Consider using Session.FileExists from WinSCP .NET assembly instead:
http://winscp.net/eng/docs/library
http://winscp.net/eng/docs/library_session_fileexists

PowerShell script may be the easiest to use for you:
http://winscp.net/eng/docs/library_session_fileexists#powershell

2) Share the .XML log with us (logfilepath) + make WinSCP generate session log and share that too:

Code:
exec = shell.Exec("\"" + WINSCP + "\" /xmllog=\"" + logfilepath + "\" /log=session.log");
CBW

Guest


The problem was simple. Server 2003 had not had WinSCP updated in a long time. I updated it and the log generated xml as desired. Problem solved! Thanks. I now have a 100% working script that checks if a file exists, then acts accordingly.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License