Board logo

标题: 请教如何判断FTP服务器中文件夹是否存在! [打印本页]

作者: cguzh     时间: 2010-7-12 11:36    标题: 请教如何判断FTP服务器中文件夹是否存在!
我需要登录到一个FTP服务器上,上传文件。比如MPUT,BIN命令什么的都晓得。但有个问题是,我想FTP登录后先判断文件夹是否存在。我知道DOS中可以有命令直接判断本地的。比如 if not exist文件夹是否存在,但我登录到FTP 后这样写就不行了。 谢谢!

作者: wwbh     时间: 2010-9-4 21:02
www.dostips.com/DtTipsFtpBatch ... hi.baidu .com/wangbaohua3/blog/item/d347e20a503146e937d1220c.html @Echo Off Setlocal Enabledelayedexpansion REM -- Define File Filter, i.e. files with extension .txt Set FindStrArgs=/E /C:".txt" REM -- Extract Ftp Script to create List of Files Set "FtpCommand=ls" Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp" Rem Notepad "%temp%\%~n0.ftp" REM -- Execute Ftp Script, collect File Names Set "FileList=" For /F "Delims=" %%A In ('"Ftp -v -i -s:"%temp%\%~n0.ftp"|Findstr %FindStrArgs%"') Do ( Call Set "FileList=%%FileList%% "%%A"" ) REM -- Extract Ftp Script to upload files that don't exist in remote folder Set "FtpCommand=mput" For %%A In (%FileList%) Do set "Exist["%%~A"]=Y" For /F "Delims=" %%A In ('"dir /b "%localdir%"|Findstr %FindStrArgs%"') Do ( If Not defined Exist["%%~A"] Call Set "FtpCommand=%%FtpCommand%% "%%~A"" ) Call:extractFileSection "[Ftp Script 1]" "-">"%temp%\%~n0.ftp" rem Notepad "%temp%\%~n0.ftp" For %%A In (%FtpCommand%) Do Echo.%%A REM -- Execute Ftp Script, download files ftp -i -s:"%temp%\%~n0.ftp" Del "%temp%\%~n0.ftp" GOTO:EOF :extractFileSection StartMark EndMark FileName -- extract a section of file that is defined by a start and end mark :: -- [IN] StartMark - start mark, use '...:S' mark to allow variable substitution :: -- [IN,OPT] EndMark - optional end mark, default is first empty line :: -- [IN,OPT] FileName - optional source file, default is THIS file :$created 20080219 :$changed 20100205 :$categories ReadFile :$source www.dostips.com SETLOCAL Disabledelayedexpansion set "bmk=%~1" set "emk=%~2" set "src=%~3" set "bExtr=" set "bSubs=" if "%src%"=="" set src=%~f0& rem if no source file then assume THIS file for /f "tokens=1,* delims=]" %%A in ('find /n /v "" "%src%"') do ( if /i "%%B"=="%emk%" set "bExtr="&set "bSubs=" if defined bExtr if defined bSubs (call echo.%%B) ELSE (echo.%%B) if /i "%%B"=="%bmk%" set "bExtr=Y" if /i "%%B"=="%bmk%:S" set "bExtr=Y"&set "bSubs=Y" ) EXIT /b

作者: etmanc     时间: 2010-9-4 23:47
谢了,楼主