用Javascript来生成ftp脚本的小例子

时间:2021-05-18

程序也很简单,就是遍历一下本地目录,然后产生一堆ftp命令。
复制代码 代码如下:
function matchDemo(strFolderName)

{

var s;

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

s = strFolderName.match(re);

return(s);

}

function init()

{

strScript ="open 192.168.1.32 \n";

strScript+="user sybase 111111 \n";

strScript+="bin\n";

strScript+="prompt\n";

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+="bye\n";

WScript.Echo(strScript);

}

else

{

WScript.Echo("Bad Folder Name");

}

声明:本页内容来源网络,仅供用户参考;我单位不保证亦不表示资料全面及准确无误,也不保证亦不表示这些资料为最新信息,如因任何原因,本网内容或者用户因倚赖本网内容造成任何损失或损害,我单位将不会负任何法律责任。如涉及版权问题,请提交至online#300.cn邮箱联系删除。

相关文章