
下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、bat脚本:将本地昨天生成的文件,上传到服务器由于工作需要,平生第一次用windows的dos写脚本。 需求:本地有个软件,天天生成相应的log文件,并保存在以日期时光为名目的文件夹下。然后需要在后一天,将前一天生成的log文件及文件夹上传到一个日志服务器举行保存。 实现工具:bat脚本,nc工具,方案任务 其中,由于系统默认的ftp指令行,不支持passive模式,而port模式下,需要修改或开启log生成端服务器的防火墙,需要终于改用网络上免费的小工具ncftp,这个小工具比系统自带的强大了n倍,支持指令行,支持pasv模式也可以切换port模式,还支持断点续传,上传胜利后删除本地文件等。
2、 实现步骤: 1)转到脚本所在名目; 2)上传之前未能胜利上传的文件; 3)取到今日需要上传的文件夹名称; 4)上传今日需要上传的文件夹及文件; 5)假如胜利,删除本地文件,假如不胜利,将文件夹移到备份名目; 6)删除空名目; 以下是详细的脚本内容(英文版系统): - echo off dt=%:10,4%date:4,2%date:7,2% set batpath=%dp0 set dname= rem turn to bat's path %d0 %batpath% bak nul 2 nul rem re-upload bak log directory and file to
3、nms server type %batpath%evtlog.txt | ftpfail nul 2 nul if %errorlevel% equ 0 goto reupload if %errorlevel% neq 0 goto reupend :reupload echo -%dt% re-upload bak log- 2 %batpath%evtlog.txt 1 2 %batpath%ftpput -u adminisator -p password -r 5 -z -r -dd 0 /3 %batpath%bak* 2 %batpa
4、th%evtlog.txt 1 2 if %errorlevel% equ 0 goto cleanrelog if %errorlevel% neq 0 goto reupfailed :cleanrelog cd. %batpath%evtlog.txt for /f tokens=* %a in ('dir /b /ad /s %batpath%bak| /r') do rd %a /q 2 nul goto reupend :reupfailed echo %dt%:ftpfailed reupload files the day before yesterday fa
5、iled! 2 %batpath%evtlog.txt 1 2 goto reupend :reupend rem get the yesterday date for /d %i in (20*) do if %i lss %dt% set dname=%i if ist %dname% goto if not exist %dname% goto :eof :ncftp rem transfer yesterday log file and er to nms server echo -%dt% ftp log- 2 %batpath%evtlog.txt 1 2 %batpath%ncf
6、tpput -u administrator -p password -r 5 -z -r -dd 0 /3 %batpath%dname% 2 %batpath%evtlog.txt 1 2 if %errorlevel% equ 11 goto session if %errorlevel% equ 10 goto library if %errorlevel% equ 9 goto error if %errorlevel% equ 8 goto usage if %errorlevel% equ 7 goto url if %errorlev
7、el% equ 6 goto directoryout if %errorlevel% equ 5 goto directory if %errorlevel% equ 4 goto transfertimeout if %errorlevel% equ 3 goto transfer if %errorlevel% equ 2 goto connecttimeout if %errorlevel% equ 1 goto connect if %errorlevel% equ 0 goto ccess :success echo ncftp:0success. 2 %batpath%evtlo
8、g.txt 1 2 goto exit :connect echo ftpfailed:1could not connect to remote host. 2 %batpath%evtlog.txt 1 2 goto movefile :connecttimeout echo ftpfailed:2could not connect to remote host - timed out. 2 %batpath%evtlog.txt 1 2 goto movefile :transfer echo ftpfailed:3transfer failed. 2 %batpath%evtlog.tx
9、t 1 2 goto movefile :transfertimeout echo ftpfailed:4transfer failed - timed out. 2 %batpath%evtlog.txt 1 2 goto movefile :directory echo ftpfailed:5directory change failed. 2 %batpath%evtlog.txt 1 2 goto movefile :directorytimeout echo ftpfailed:6directory change failed - timed out. 2 %batpath%evtl
10、og.txt 1 2 goto movefile :url echo ftpfailed:7malfoed url. 2 %batpath%evtlog.txt 1 2 goto movefile :usage echo ftpfailed:8usage error. 2 %batpath%evtlog.txt 1 2 goto movefile :error echo ftpfailed:9error in login configuration file. 2 %batpath%evtlog.txt 1 2 goto movefile :library echo ftpfailed:10l
11、ibrary initialization failed. 2 %batpath%evtlog.txt 1 2 goto movefile :session echo ftpfailed:11session initialization failed. 2 %batpath%evtlog.txt 1 2 goto movefile :movefile rem move yesterday log directory s and files to the destination directory bak move /y %batpath%dname% %batpath%bak%dname% 2 %batpath%evtlog.txt 1 2 if %errorlevel% neq 0 echo moveerror:a plie file name exists, or the file cannot be found. 2 %batpath%evtlog.
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 我国航空运输布局AviationTourismGeogra
- 2025年新零售环境下实体书店的线上线下联动策略报告
- 早产儿腹胀护理查房
- 工业互联网平台网络切片技术在智能工厂设备远程控制中的应用实践报告
- 人机工程知识培训课件
- 2025年矿山无人作业技术对环境的影响及可持续发展策略报告
- 数字化浪潮下教育科技企业商业模式创新与竞争力提升报告
- DB37/T 3656-2019地质灾害治理工程监理技术规范
- DB36/T 985-2017政府网站建设及管理规范
- 重型破伤风护理查房
- 青春期学生性教育PPT资料
- 文博考研-博物馆学名词解释
- DLT 1055-2021 火力发电厂汽轮机技术监督导则
- 安全信息管理程序
- 电工基础(中职)完整版教学课件
- (中职)《电子商务基础》第1套试卷试题及答案
- 中共中央办公厅、国务院办公厅关于进一步稳定和完善农村土地承包关系的通知中办发〔1997〕16号,1997年6
- 计算机应用基础-终结性考试试题国开要求标准
- 预制梁场验收及质量管理实施细则
- 鞋业订货单模版
- 大理石打磨工程装饰协议合同
评论
0/150
提交评论