5

批处理脚本如下:

>>ftp.txt open ftp.site.com
>>ftp.txt username
>>ftp.txt password
>>ftp.txt directoryname
>>ftp.txt quit
ftp -s ftp.txt

如何删除文件夹'directoryname'中的所有文件?

4

2 回答 2

14

将以下命令放入 ft​​p.txt 并按如下方式运行以完成此任务:
ftp -i -s:ftp.txt

ftp.txt 的内容:

open ftp.site.com
username
password
cd directoryname
mdelete *
quit
于 2012-02-24T08:35:31.833 回答
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
于 2018-06-07T22:16:45.377 回答