【发布时间】:2018-07-05 22:23:06
【问题描述】:
我正在制作.bat 代码以将.txt 文件发送到我的 ftp 服务器上的特定文件夹。但我也想要一种方法来检查这些文件是否真的上传了。我在互联网上搜索了很多,不幸的是,我意识到使用.bat 命令无法完成。
所以我尝试使用另一种方式:.bat 将发送文件,然后将其带回文件夹,如果文件已存在于文件夹中,则会显示文件已成功上传的消息。
我在下面做了这个脚本,但是“检查是否已上传”的部分工作不正常。
有人可以帮助我吗?
@echo off
@setlocal enableextensions
@cd /d "%~dp0"
mode 34,12
color 0a
Ping www.google.nl -n 1 -w 1000 >nul 2>nul
if errorlevel 1 (set internet=Nao foi possivel se conectar ao servidor) else (set internet=Conectado) >nul 2>nul
echo %internet%
if "%internet%"=="No connection" goto 1
if "%internet%"=="Conected" goto 2
:1
echo No connection
echo.
echo Try later...
echo.
pause
exit
:2
( echo open ftp.xxxxxxxxxxx.com
echo xxxxxxx
echo xxxxxxx
echo ascii
echo lcd "c:\Vendas Pay&Go\files"
echo cd "Vendas Cartões Pay&Go"
echo cd "ECO"
echo mput *.txt
echo bye
)> %temp%\ftpsend.dat
ftp -i -s:%temp%/ftpsend.dat >nul 2>nul
del /f /s /q %temp%\ftpsend.dat >nul 2>nul
( echo open ftp.xxxxxxx.com
echo xxxxxxx
echo xxxxxxx
echo ascii
echo lcd "c:\Vendas Pay&Go\files"
echo cd "Vendas Cartões Pay&Go"
echo cd "ECO"
echo mget *.txt
echo bye
)> %temp%\ftpsend.dat
ftp -i -s:%temp%/ftpsend2.dat >nul 2>nul
del /f /s /q %temp%\ftpsend2.dat >nul 2>nul
if %*.txt% exist goto3
:4
echo File was not uploaded
pause
:3
echo File Uploaded.
del /s /f /q "c:\Vendas Pay&Go\files\*.txt"
【问题讨论】:
-
如果您捕获 FTP 命令的详细输出,它将告诉您文件是否已成功上传。无需尝试重新下载即可查看是否上传成功。我从未见过任何日志文件告诉我文件已成功上传,但在 ftp 服务器上看不到该文件。我每天运行数十个自动 FTP 批处理文件,解析详细输出从来都不是问题。
-
不管前面的评论如何,如果你真的阅读了
IF命令的帮助文件,你会看到这个用法语法:IF EXIST filename command。那么根据这些信息,你做错了什么? -
@Squashman 我猜脚本中有一些错误。无论如何,我正在检查它。我喜欢你所说的关于 ftp 的详细输出,但我只是希望它显示在一个分隔的 echo 中,而不是与所有 ftp echo 一起显示。
-
ftp -i -s:%temp%/ftpsend.dat | find /I "file successfully transferred" -
@Squashman 好!我尝试使用条件
if使用单词file sucessufully transferred作为参考来进行echo操作。但是什么也没发生,也许我猜是因为这是一个内部代码显示。如果上传成功,我希望它显示:File transfered或者如果没有上传No transfered. Try again later
标签: batch-file ftp