>> Products   |   >> Quick start   |   >> FAQ   |   >> Store   |   >> Registration   |   >> Company   |   >> Contact
    Automation objects exposure


The FTPSync automation solution exports some very useful functionality via COM automation objects. They can be used in variety of scripting languages that support Microsoft automation technology. Standard windows scripting languages are Java script and VB script. You also can install language of your choice (Pearl, Python etc) to use objects functionality. These automation objects extend functionality of script languages for effective automation scripts writing.

Below are examples of objects usage written in java script language with some explanations.

  • Zip Object - Object that Zips/Unzips folders and files.
  • FTP Object - FTP client.
  • Email Object - SMTP client.
  • Folder Object - Object that mounts, unmounts and access password protected UNC path or mapped drive on LAN. May be useful in case service running under 'LocalSystem' account (default) or path not mounted under system user account.

Zip/Unzip automation script sample

// ZipSample.js
main();

function main()
{  
  var CoZip = null; 
  try
  {
    CoZip = WScript.CreateObject("Zip.CoZip");
    // Add few files and folders to zip archive 
    // All paths must be relative to current directory and existing
    // Root of archive equals the application current directory by default 
    CoZip.OpenZip("test.zip");
    CoZip.AddFile("Shared");         // add folder
    CoZip.AddFile("ZipUnzip\\zlib"); // add folder
    CoZip.AddFile("CoZip.cpp");      // add file
    CoZip.AddFile("CoZip.h");        // add file
    CoZip.AddFile("CoZip.rgs");      // add file
    CoZip.CloseZip();

    // Sample where we set archive root directory, 
    // Archive root directory not equals application current directory
    // All file paths must be absolute, located inside of archive root 
    // directory and existing
    CoZip.ArchiveRootDirectory = "d:\\japp";
    CoZip.OpenZip("test2.zip");   
    CoZip.AddFile("d:\\japp\\chem");                    // add folder
    CoZip.AddFile("d:\\japp\\Struts-and-JSP2-EL.pdf");  // add file
    // add file that is not existing in archive root directory, 
    // second parameter is relative path of file in archive
    CoZip.AddFile2("c:\\Program Files\\Far\\Far.exe", "chem\\Far.exe");
    // add folder that is not existing in archive root directory
    // second parameter is relative path of folder in archive
    CoZip.AddFile2("c:\\Program Files\\ISM", "ISM");
    CoZip.CloseZip();

    // Zip one file or one folder operations sample (new archives created)
    // All file paths must be relative to archive root directory 
    // and existing inside this directory
    // The output zip file path may be absolute or relative
    CoZip.ArchiveRootDirectory = "D:\\temp\\orbex4\\Zip";
    CoZip.ZipFolder("test3.zip", "Shared");
    CoZip.ZipFile("test4.zip", "Zip.sln");
    CoZip.ZipFolder("d:\\test5.zip", "ZipUnzip");
  
    // Unzip archive in specified folder
    // second parameter must be an existing folder
    CoZip.Unzip("d:\\test5.zip", "d:\\OutputZip");
  }
  catch(e)
  {
    var strError = "Unknown Zip Error";
    if(e.description.length != 0)
    {
      strError = "Zip Error: " + e.description;
    }
    WScript.Echo(strError);
    return;
  }
  CoZip = null;
}

FTP automation script sample

// FTPsample.js
main();

function main()
{

  // All FTP constants listed here
  // DataTypeEnum Enumeration -> DataType property
  Binary = 0;
  ASCII = 1;

  // TransferModeEnum Enumeration -> TransferMode property
  Active = 0;
  Passive = 1;

  // ActionModeEnum Enumeration -> ActionMode property
  Synchronous = 0;
  Asynchronous = 1;

  // The ProxyTypeEnum enumeration -> ProxyType property
  NONE = 0;
  SOCKS4 = 1;
  SOCKS4A = 2;
  SOCKS5 = 3;
  HTTP = 4;

  // The ListTypeEnum enumeration -> ListType property
  LISTLONG = 0;
  LISTSHORT = 1;  

  // FileTypeEnum Enumeration -> FileType property
  FTPUNKNOWN = 0;
  FTPLINK = 1;
  FTPFOLDER = 2;
  FTPFILE = 3;
  
  var CoFTP = null; 
  try
  {
    CoFTP = WScript.CreateObject("FTP102.CoFTP");
    
    // Download sample    
    CoFTP.Host = "ftp.microsoft.com";
    CoFTP.User = "anonymous";
    CoFTP.Password = "mail@mail.com";
    CoFTP.Port = 21;
    // Connected to host
    CoFTP.Connect();
    // login to FTP server
    CoFTP.Login();    
    // If login operation success then download file
    CoFTP.Download("/ResKit/win2000/toolhelp.zip", "toolhelp.zip");
    CoFTP.Close();
    
    // optionally set proxy
    // CoFTP.ProxyType = SOCKS4;
    // CoFTP.ProxyHost = "127.0.0.1";
    // CoFTP.ProxyPort = 1080;
    // CoFTP.ProxyUser = "oleg";
    // CoFTP.ProxyPassword = "secret";

    // Upload sample
    CoFTP.Host = "127.0.0.1";
    CoFTP.User = "anonymous";
    CoFTP.Password = "mail@mail.com";
    CoFTP.Port = 21;
    // Connect to host
    CoFTP.Connect();
    // login to FTP server
    CoFTP.Login();

    // change transfer mode
    CoFTP.TransferMode = Passive;
    // set data type
    CoFTP.DataType = Binary;    

    // If login operation success then upload file
    CoFTP.Upload("/stat/AStar.zip", "d:\\AStar.zip");
    // change current directory
    CoFTP.ChDir("/stat");
    // make and remove directory
    CoFTP.Mkd("TestDir");
    CoFTP.Rmd("TestDir");

    CoFTP.Close();
  }
  catch(e)
  {
    var strError = "Unknown FTP Error";
    if(e.description.length != 0)
    {
      strError = "FTP Error: " + e.description;
    }
    WScript.Echo(strError);
  }
  CoFTP = null;
}

 

Email automation script sample

// EmailSample.js
main();

function main()
{
  var CoMail = null; 
  try
  {
     CoMail = WScript.CreateObject("ATLMailer.CoMailer");

     CoMail.SMTPServer = "mail.server.com";
     CoMail.UserPassword = "";
     CoMail.UserLogin = "";
     CoMail.From = "user123@gmail.com";
     CoMail.CC = "max123@gmail.com";
     CoMail.Subject = "Test Message";
     CoMail.MessageText = "Hi there";  
     CoMail.AttachmentPath = "d:\\sysimg.zip";
     CoMail.AddRecipient("virgo@gmail.com");
     CoMail.Send();
     CoMail.RemoveAllRecipients();
  }
  catch(e)
  {
    var strError = "Unknown Email Error";
    if(e.description.length != 0)
    {
      strError = "Email Error: " + e.description;
    }
    WScript.Echo(strError);
  }
  CoMail = null;
}

Object that mounts, unmounts and access password protected UNC path or mapped drive on LAN. May be useful in case service running under 'LocalSystem' account (default) or path not mounted under system user account.

// MountSample.js
main();

function main()
{  
  var CoFolder = null; 
  try
  {
    CoFolder = WScript.CreateObject("Folder.CoFolder");
    CoFolder.User = "admin";
    CoFolder.Password = "password";
    CoFolder.MountPath = "\\\\192.168.224.1\\e$";
    CoFolder.MapDrive = true;
    CoFolder.LocalDrive = "Q:";
    CoFolder.Mount();
    if (CoFolder.Mounted)
    {
      try
      {
         // use relative path
         CoFolder.GetFile("c:\\ModCleanup.zip", 
                          "ftpdata\\olegbox\\ModCleanup.zip");
         // use full network mapped drive path
         CoFolder.GetFile("c:\\ModCleanup.zip", 
                          "Q:\\ftpdata\\olegbox\\ModCleanup.zip");
         // use full network path
         CoFolder.GetFile("c:\\ModCleanup.zip", 
                          "\\\\192.168.224.1\\e$\\ftpdata\\olegbox\\ModCleanup.zip");
         // use relative path
         CoFolder.PutFile("c:\\ModCleanup.zip", 
                          "ftpdata\\olegbox\\ModCleanup.zip");
         // use full network mapped drive path
         CoFolder.PutFile("c:\\ModCleanup.zip", 
                          "Q:\\ftpdata\\olegbox\\ModCleanup.zip");
         // use full network path
         CoFolder.PutFile("c:\\ModCleanup.zip", 
                          "\\\\192.168.224.1\\e$\\ftpdata\\olegbox\\ModCleanup.zip");
      }
      catch (e)
      {
        WScript.Echo(e.description);
      }
      CoFolder.Umount();
    }  
  }
  catch(e)
  {
    var strError = "Unknown Error";
    if(e.description.length != 0)
    {
      strError = "Error: " + e.description;
    }
    WScript.Echo(strError);
    // or use last error property
    WScript.Echo(CoFolder.LastError);
    return;
  }
  CoFolder = null;
}
   © Copyright 2004-2008 Industrial software managment. All Rights Reserved.    |     >>   11/20/2008 7:15:24 PM