Differences

This shows you the differences between the selected revisions of the page.

2015-10-15 2015-12-14
MS standard is to have opening brace on new line (martin) Add JScript example (109.81.210.121)
Line 325: Line 325:
</code> </code>
 +==== [[JScript]] JScript example ===
 +<code javascript>
 +<job>
 +<reference object="WinSCP.Session" />
 +<script language="JScript">
 +
 +function SessionEvent_FileTransferred(sender, e)
 +{
 +    if (e.Error == null)
 +    {
 +        WScript.Echo("Upload of "+e.FileName+" succeeded");
 +    }
 +    else
 +    {
 +        WScript.Echo("Upload of " + e.FileName + " failed: " + e.Error);
 +    }
 +
 +    if (e.Chmod != null)
 +    {
 +        if (e.Chmod.Error == null)
 +        {
 +            WScript.Echo("Permisions of "+e.Chmod.FileName+" set to " + e.Chmod.FilePermissions);
 +        }
 +        else
 +        {
 +            WScript.Echo("Setting permissions of "+e.Chmod.FileName+" failed: " + e.Chmod.Error);
 +        }
 +    }
 +    else
 +    {
 +        WScript.Echo("Permissions of "+e.Destination+" kept with their defaults");
 +    }
 +
 +    if (e.Touch != null)
 +    {
 +        if (e.Touch.Error == null)
 +        {
 +            WScript.Echo("Timestamp of "+e.Touch.FileName+" set to " + e.Touch.LastWriteTime);
 +        }
 +        else
 +        {
 +            WScript.Echo("Setting timestamp of "+e.Touch.FileName+" failed: " + e.Touch.Error);
 +        }
 +    }
 +    else
 +    {
 +        // This should never happen during "local to remote" synchronization
 +        WScript.Echo("Timestamp of " + e.Destination + " kept with its default (current time)");
 +    }
 +}
 +
 +try
 +{
 +    // Setup session options
 +    var sessionOptions = WScript.CreateObject("WinSCP.SessionOptions");
 +    sessionOptions.Protocol = 0;//Protocol_Sftp;
 +    sessionOptions.HostName = "example.com";
 +    sessionOptions.UserName = "user";
 +    sessionOptions.Password = "mypassword";
 +    sessionOptions.SshHostKeyFingerprint = "ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx";
 +
 +    var session = WScript.CreateObject("WinSCP.Session", "SessionEvent_");
 +
 +    try
 +    {
 +        // Connect
 +        session.Open(sessionOptions);
 +
 +        // Synchronize files
 +        var synchronizationResult = session.SynchronizeDirectories(
 +            0 /* Local */, "C:\\work\\files", "/home/user/files", false)
 +
 +        // Throw on any error
 +        synchronizationResult.Check()
 +    }
 +    finally
 +    {
 +        // Disconnect, clean up
 +        session.Dispose();
 +    }
 +}
 +catch (e)
 +{
 +    WScript.Echo("Error: " + e.message);
 +    WScript.Quit(1);
 +}
 +</script>
 +</job>
 +</code>
==== Real-Life Example ==== ==== Real-Life Example ====

Last modified: by 109.81.210.121