利用windows系统ftp命令编写的BAT文件上传[转]
在开发中往往需要将本地的程序上传到服务器,而且用惯了linux命令的人来说。在windows下就比较麻烦了。为了方便特编写一个BAT程序来帮助需要这样功能的人。如果用其他IDE工具自带的FTP功能也可以,^_^!
     命令: todev.bat /index.asp  默认d:\cnweb为网站的根目录。
     我的 http://www.lawcar.cn/ http://www.myitcar.com/ http://www.stockcar.cn/ http://www.lunwencar.com/ 都是靠这样的方法维护。
 @IF "%1"=="" goto error_parm
@IF "%1"=="" goto error_parm @IF "%2"=="" goto error_parm
@IF "%2"=="" goto error_parm
 @SETLOCAL
@SETLOCAL @set server=192.168.10.199
@set server=192.168.10.199 @set username=
@set username= @set password=
@set password=
 @echo 是否上传 d:\cnweb\%1\%2 到dev服务器!
@echo 是否上传 d:\cnweb\%1\%2 到dev服务器!
 @echo off
@echo off CHOICE /C YN /M "确认请按 Y,否请按N退出"
CHOICE /C YN /M "确认请按 Y,否请按N退出" if errorlevel 255 goto no
if errorlevel 255 goto no if errorlevel 2 goto no
if errorlevel 2 goto no if errorlevel 1 goto yes
if errorlevel 1 goto yes 

 :no
:no @echo on
@echo on @echo 没有任何文件上传到DEV.
@echo 没有任何文件上传到DEV. @goto end
@goto end 
 :yes
:yes
 IF not EXIST d:\cnweb\%1\%2 goto error2
IF not EXIST d:\cnweb\%1\%2 goto error2
 echo open %server% > ftp.txt
echo open %server% > ftp.txt echo user %username% >> ftp.txt
echo user %username% >> ftp.txt echo %password% >> ftp.txt
echo %password% >> ftp.txt echo cd %1 >> ftp.txt
echo cd %1 >> ftp.txt echo bye>> ftp.txt
echo bye>> ftp.txt ftp -s:ftp.txt -n | find "550"
ftp -s:ftp.txt -n | find "550" if not errorlevel 1 @goto error
if not errorlevel 1 @goto error rem del ftp.txt ftperror.txt
rem del ftp.txt ftperror.txt
 echo open %server% > ftp.txt
echo open %server% > ftp.txt echo user %username% >> ftp.txt
echo user %username% >> ftp.txt echo %password% >> ftp.txt
echo %password% >> ftp.txt echo cd %1 >> ftp.txt
echo cd %1 >> ftp.txt echo put d:\cnweb\%1\%2 >> ftp.txt
echo put d:\cnweb\%1\%2 >> ftp.txt echo bye>> ftp.txt
echo bye>> ftp.txt ftp -s:ftp.txt -n | find "Invalid"
ftp -s:ftp.txt -n | find "Invalid"  if not errorlevel 1 @goto error3
if not errorlevel 1 @goto error3 rem del ftp.txt ftperror.txt
rem del ftp.txt ftperror.txt
 @echo on
@echo on @echo 上传DEV完成.
@echo 上传DEV完成. @goto putok
@goto putok 
 :error
:error @echo 服务器目录错误 %1
@echo 服务器目录错误 %1  rem del ftp.txt ftperror.txt
rem del ftp.txt ftperror.txt @goto end
@goto end
 :error2
:error2 @echo 本地目录错误 d:\cnweb\%1
@echo 本地目录错误 d:\cnweb\%1 @del ftp.txt ftperror.txt
@del ftp.txt ftperror.txt @goto end
@goto end
 :error3
:error3 @echo 上传文件错误 d:\cnweb\%1\%2
del ftp.txt ftperror.txt
@goto end
:putok
@echo 上传成功 %1 %2 !
@rem del ftp.txt ftperror.txt
@goto end
:error_parm
@echo 参数错误,正确格式: todev 相对路径 文件名
@goto end
:end
@echo Bye.
@ENDLOCAL
@echo 上传文件错误 d:\cnweb\%1\%2
del ftp.txt ftperror.txt
@goto end
:putok
@echo 上传成功 %1 %2 !
@rem del ftp.txt ftperror.txt
@goto end
:error_parm
@echo 参数错误,正确格式: todev 相对路径 文件名
@goto end
:end
@echo Bye.
@ENDLOCAL 
                    
                     
                    
                 
                    
                 
 
                
            
        