批处理脚本如下:
>>ftp.txt open ftp.site.com
>>ftp.txt username
>>ftp.txt password
>>ftp.txt directoryname
>>ftp.txt quit
ftp -s ftp.txt
如何删除'directoryname'文件夹中的所有文件?
答案 0 :(得分:14)
将以下命令放在ftp.txt中并按如下方式运行以完成此任务:
ftp -i -s:ftp.txt
ftp.txt的内容:
open ftp.site.com
username
password
cd directoryname
mdelete *
quit
答案 1 :(得分:0)
这是一个完整而安全的解决方案!
有一点是你必须要有一个' y'对于每个文件,如果你有太多文件并不重要,那么只需几秒就可以得到数百个文件并提供你永远无法看到的错误信息。
临时文件与bat文件在同一文件夹中创建,并将被脚本删除。
即使dir *显示子文件夹中的所有文件,您也可以使用mdelete *。
@echo off
echo.
:MENU
cls
echo.
echo What do you want to do?
echo.
echo 1 - Delete all files in a folder at FTP using ftp batch script
echo 2 - Cancel
echo 3 - Logout
echo.
set /p choice=
if %choice%==1 goto sure
if %choice%==2 goto cancel
if %choice%==3 goto ?
echo Invalid Choice
echo.
pause
goto MENU
:sure
echo.
echo Are you sure to delete all files y/n
echo.
set /p choice=
if %choice%==y goto delete
if %choice%==Y goto delete
if %choice%==n goto cancel
if %choice%==N goto cancel
echo Invalid Choice
echo.
pause
goto sure
:delete
echo open my-domain.com> temp.txt
echo username>> temp.txt
echo password>> temp.txt
echo cd public_html/directoryname>> temp.txt
echo mdelete *.*>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo y>> temp.txt
echo quit>> temp.txt
REM Start FTP and send it to the script
ftp -s:temp.txt
REM delete the temp-file
del temp.txt
cls
echo.
echo All files are deleted!
echo.
pause
goto MENU
:cancel
echo.
echo You have cancelled the erasement!
echo.
Pause
goto MENU