| 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
main();
function main()
{
var CoZip = null;
try
{
CoZip = WScript.CreateObject("Zip.CoZip");
CoZip.OpenZip("test.zip");
CoZip.AddFile("Shared");
CoZip.AddFile("ZipUnzip\\zlib");
CoZip.AddFile("CoZip.cpp");
CoZip.AddFile("CoZip.h");
CoZip.AddFile("CoZip.rgs");
CoZip.CloseZip();
CoZip.ArchiveRootDirectory = "d:\\japp";
CoZip.OpenZip("test2.zip");
CoZip.AddFile("d:\\japp\\chem");
CoZip.AddFile("d:\\japp\\Struts-and-JSP2-EL.pdf");
CoZip.AddFile2("c:\\Program Files\\Far\\Far.exe", "chem\\Far.exe");
CoZip.AddFile2("c:\\Program Files\\ISM", "ISM");
CoZip.CloseZip();
CoZip.ArchiveRootDirectory = "D:\\temp\\orbex4\\Zip";
CoZip.ZipFolder("test3.zip", "Shared");
CoZip.ZipFile("test4.zip", "Zip.sln");
CoZip.ZipFolder("d:\\test5.zip", "ZipUnzip");
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
main();
function main()
{
Binary = 0;
ASCII = 1;
Active = 0;
Passive = 1;
Synchronous = 0;
Asynchronous = 1;
NONE = 0;
SOCKS4 = 1;
SOCKS4A = 2;
SOCKS5 = 3;
HTTP = 4;
LISTLONG = 0;
LISTSHORT = 1;
FTPUNKNOWN = 0;
FTPLINK = 1;
FTPFOLDER = 2;
FTPFILE = 3;
var CoFTP = null;
try
{
CoFTP = WScript.CreateObject("FTP102.CoFTP");
CoFTP.Host = "ftp.microsoft.com";
CoFTP.User = "anonymous";
CoFTP.Password = "mail@mail.com";
CoFTP.Port = 21;
CoFTP.Connect();
CoFTP.Login();
CoFTP.Download("/ResKit/win2000/toolhelp.zip", "toolhelp.zip");
CoFTP.Close();
CoFTP.Host = "127.0.0.1";
CoFTP.User = "anonymous";
CoFTP.Password = "mail@mail.com";
CoFTP.Port = 21;
CoFTP.Connect();
CoFTP.Login();
CoFTP.TransferMode = Passive;
CoFTP.DataType = Binary;
CoFTP.Upload("/stat/AStar.zip", "d:\\AStar.zip");
CoFTP.ChDir("/stat");
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
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.
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
{
CoFolder.GetFile("c:\\ModCleanup.zip",
"ftpdata\\olegbox\\ModCleanup.zip");
CoFolder.GetFile("c:\\ModCleanup.zip",
"Q:\\ftpdata\\olegbox\\ModCleanup.zip");
CoFolder.GetFile("c:\\ModCleanup.zip",
"\\\\192.168.224.1\\e$\\ftpdata\\olegbox\\ModCleanup.zip");
CoFolder.PutFile("c:\\ModCleanup.zip",
"ftpdata\\olegbox\\ModCleanup.zip");
CoFolder.PutFile("c:\\ModCleanup.zip",
"Q:\\ftpdata\\olegbox\\ModCleanup.zip");
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);
WScript.Echo(CoFolder.LastError);
return;
}
CoFolder = null;
}
|