欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

实现FTP整站上传的批处理代码

程序员文章站 2022-03-22 16:26:02
@echo off rem 设置ftp服务器地址 set ftpip=192.168.0.2 rem 设置ftp用户名 set ftpuser=myuser...
@echo off
rem 设置ftp服务器地址
set ftpip=192.168.0.2
rem 设置ftp用户名
set ftpuser=myuser
rem 设置ftp密码
set ftppass=mypass
rem 设置待上传的本地文件夹目录
set upfolder=c:/test

rem 生成待上传的本地文件夹列表
type nul>%temp%/folderlist.txt
for /r "%upfolder%" %%a in (.) do (
  set fullname=%%a
  setlocal enabledelayedexpansion
  set foldername=!fullname:%upfolder%=!
  set foldername=!foldername:~1,-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 "%%a"
    echo cd "/%%a"
    echo mput "%upfolder%/%%a/*.*"
  )
)
>>"%temp%/ftpfile.txt" echo ! rd /s /q "%upfolder%"
>>"%temp%/ftpfile.txt" echo ! md "%upfolder%"
>>"%temp%/ftpfile.txt" echo bye
ftp -v -i -s:"%temp%/ftpfile.txt" %ftpip%