用Javascript來生成ftp腳本

昨天閑著沒事,又因為工作需要,寫瞭一個腳本,用來做ftp。
    當然不是直接做ftp,而是產生一個ftp的腳本,供ftp命令使用。

    程序也很簡單,就是遍歷一下本地目錄,然後產生一堆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; www.aiwalls.com

    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");

    }

 

摘自 黑黑博客

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。