本地文件夹备份至FTP
1 设置ftp及目录信息
2 生成文件夹列表
3 逐一mkdir并mput

批处理如下:

@echo on
rem 设置FTP服务器地址
set ftpIP=192.168.2.247
rem 设置FTP用户名
set ftpUser=wisq
rem 设置FTP密码
set ftpPass=wisq
rem 设置待上传的本地文件夹目录
set UpFolder=D:\test\
rem 设置FTP子文件夹
set ftpFolder=\aishequ

rem 生成待上传的本地文件夹列表
type nul>%temp%\FolderList.txt
for /r "%UpFolder%" %%a in (.) do (
    set FullName=%%a
    setlocal enabledelayedexpansion
    set FolderName=!FullName:%UpFolder%=!
    set FolderName=!FolderName:~0,-2!
    echo,!FolderName!>>%temp%\FolderList.txt
    endlocal
)
>"%temp%\ftpFile.txt" echo,%ftpUser%
>>"%temp%\ftpFile.txt" echo,%ftpPass%
>>"%temp%\ftpFile.txt" echo bin
>>"%temp%\ftpFile.txt" (
    for /f "usebackq tokens=*" %%a in ("%temp%\FolderList.txt") do (
        echo cd \
        echo mkdir "%ftpFolder%\%%a"
        echo cd "%ftpFolder%\%%a"
        echo mput "%UpFolder%\%%a\*"
    )
)
>>"%temp%\ftpFile.txt" echo ! md "%UpFolder%"
>>"%temp%\ftpFile.txt" echo bye
ftp -v -i -s:"%temp%\ftpFile.txt" %ftpIP%

PAUSE

backup2ftp.txt

标签: none

添加新评论