A small example of using JavaScript to generate an FTP script

Source: Internet
Author: User
Tags ftp ftp commands mkdir

The program is also very simple, is to traverse the local directory, and then generate a bunch of FTP commands.

Copy Code code as follows:


function Matchdemo (strfoldername)

{

var s;

var re =/200d{5}/ig;

s = Strfoldername.match (re);

return (s);

}

function init ()

{

Strscript = "Open 192.168.1.32 n";

strscript+= "User Sybase 111111 n";

strscript+= "Binn";

strscript+= "PROMPTN";

strscript+= "Cd/hisdata/olddata n";

Dicwhitelist = new ActiveXObject ("Scripting.Dictionary");

Dicwhitelist.add ("20051205_pihou", "");

Dicwhitelist.add ("20051206_pihou", "");

Dicwhitelist.add ("20060701_pihou", "");

}

function Enumsubfolder (Osubfolder)

{

var efolders=new enumerator (osubfolder.subfolders);

var s= "";

if (Efolders.atend ())

{

return s;

}

Else

{

for (;!efolders.atend (); Efolders.movenext ())

{

s+= "LCD" ";

S+=efolders.item ();

s+= "" N ";

s+= "Mput *.*n";

}

return s;

}

}

function Checklist (strtobechecked)

{

Return!dicwhitelist.exists (strtobechecked);

}

var strscript,dicwhitlist;

var sfolderpath= "E:";

var ofs=new activexobject ("Scripting.FileSystemObject");

Init ();

if (ofs.folderexists (Sfolderpath))

{

WScript.Echo ("Valid folder");

var ofolders=ofs.getfolder (Sfolderpath);

var efolders=new enumerator (ofolders.subfolders);

if (Efolders.atend ())

{

Strscript + + "mkdir";

Strscript + + ofs.getbasename (Sfolderpath);

Strscript + = "n";

}

Else

{

for (;!efolders.atend (); Efolders.movenext ())

{

Strtargetfoldername=matchdemo (Efolders.item () + "");

if (Strtargetfoldername==null | | Checklist (Ofs.getbasename (Efolders.item ()))

Continue

Strtmpfoldername= "" "+ofs.getbasename (Efolders.item ()) +" ";

Strscript = "MkDir"

Strscript + = Strtargetfoldername;

Strscript + = "n";

Strscript + + "CD";

Strscript + = Strtargetfoldername;

Strscript + = "n";

Strscript + + enumsubfolder (Efolders.item ());

Strscript = "LCD"

Strscript + + Efolders.item ();

Strscript + = "n";

Strscript + = "Mput *.*n";

Strscript + = "CD nlcd n";

}

}

strscript+= "Byen";

WScript.Echo (Strscript);

}

Else

{

WScript.Echo ("Bad Folder Name");

}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.