在Windows批处理脚本中按文件传输到FTP文件

时间:2015-10-30 07:29:53

标签: batch-file ftp

无法按文件传输文件到ftp。请劝告。感谢帮助

test.ftp

    open ftp2.xxx.com
    xxx
    xxxxx
下面的

是.bat

set "ftptarget=ftp://ftp2.xxx.com/"
ftp -i -s:test.ftp

for /f "delims=" %%A in ('findstr /s /m /l /c:"100000" "%source%\*"') do (copy /y "%%A" "%ftptarget%")

1 个答案:

答案 0 :(得分:0)

我很久以前发过一篇文章(我认为)确实是你想要的: http://www.howtogeek.com/50359/upload-files-to-an-ftp-site-via-a-batch-script/

此脚本将文件名作为参数,或者您可以指定包含要上载的文件列表的文本文件。如果您需要上传符合特定条件的文件(只需将DIR输出写入文本文件并提供文本文件作为参数),后一选项就非常有用。

如果没有别的,它应该提供一个如何使用内置FTP命令的工作示例。

以下是上述链接中的脚本:

@ECHO OFF
REM Usage -- save this script as "UploadToFTP.bat":
REM UploadToFTP [/L] FileToUpload
REM
REM Required Parameters:
REM  FileToUpload
REM      The file or a text file containing the list of files to be uploaded.
REM
REM Optional Parameters:
REM  /L  When supplied, the FileToUpload is read as a list of files to be uploaded.
REM      A list of files should be a plain text file which has a single file on each line.
REM      Files listed in this file must specify the full path.

SETLOCAL EnableExtensions

REM Connection information:
SET Server=
SET UserName=
SET Password=

REM ---- Do not modify anything below this line ----

SET Commands="%TEMP%SendToFTP_commands.txt"

REM FTP user name and password. No spaces after either.
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%

REM FTP transfer settings.
ECHO binary >> %Commands%

IF /I "%~1"=="/L" (
   REM Add file(s) to the list to be FTP'ed.
   FOR /F "usebackq tokens=*" %%I IN ("%~dpnx2") DO ECHO put "%%~I" >> %Commands%
) ELSE (
   ECHO put "%~dpnx1" >> %Commands%
)

REM Close the FTP connection.
ECHO close  >> %Commands%
ECHO bye    >> %Commands%

REM Perform the FTP.
FTP -d -i -s:%Commands% %Server%

ECHO.
ECHO.

REM Clean up.
IF EXIST %Commands% DEL %Commands%

ENDLOCAL