cURL:上传时如何显示进度信息?
我使用以下语法上载文件:cURL:上传时如何显示进度信息?,curl,Curl,我使用以下语法上载文件: curl --form upload=@localfilename --form press=OK [URL] 如何显示进度?Thx.这是我在一个构建脚本中使用的内容: curl "${UPLOAD_URL}" \ --progress-bar \ --verbose \ -F build="${BUILD}" \ -F version="${VERSION}" \ -F ipa="@${IPA};type=applicatio
curl --form upload=@localfilename --form press=OK [URL]
如何显示进度?Thx.这是我在一个构建脚本中使用的内容:
curl "${UPLOAD_URL}" \
--progress-bar \
--verbose \
-F build="${BUILD}" \
-F version="${VERSION}" \
-F ipa="@${IPA};type=application/octet-stream" \
-F assets="@-;type=text/xml" \
-F replace="${REPLACE}" \
-A "${CURL_FAKE_USER_AGENT}" \
<<< "${ASSETS}" \
| tee -a "${LOG_FILE}" ; test ${PIPESTATUS[0]} -eq 0
它告诉curl
在上传过程中显示进度条(而不是默认的“进度表”),并且:
| tee -a "${LOG_FILE}" ; test ${PIPESTATUS[0]} -eq 0
它将命令的输出附加到日志文件,并将其回送到stdout
。test${PIPESTATUS[0]}-eq 0
部分使此行的退出状态(在bash脚本中)与curl
命令返回的退出代码相同,而不是tee
命令的退出状态(必要,因为tee
实际上是此行执行的最后一个命令,而不是curl
)
从
man curl
:
PROGRESS METER
curl normally displays a progress meter during operations, indicating the
amount of transferred data, transfer speeds and estimated time left, etc.
curl displays this data to the terminal by default, so if you invoke curl
to do an operation and it is about to write data to the terminal, it disables
the progress meter as otherwise it would mess up the output mixing progress
meter and response data.
If you want a progress meter for HTTP POST or PUT requests, you need to
redirect the response output to a file, using shell redirect (>), -o [file]
or similar.
It is not the same case for FTP upload as that operation does not spit out
any response data to the terminal.
If you prefer a progress "bar" instead of the regular meter, -# is your
friend.
OPTIONS
-#, --progress-bar
Make curl display progress as a simple progress bar instead of the
standard, more informational, meter.
我在接受答案的命令重定向方面遇到了问题,发现
-o
选项将把响应输出放在一个允许显示进度条的文件中
curl --progress-bar \
-o upload.txt \
-H ${SOME_AUTH_HEADER} \
-T ${SOME_LARGE_FILE} \
"${UPLOAD_URL}"
这只是获得所需结果的另一个选项
注意:在手册页中强调这一行对于理解为什么在仅指定
--进度条
时进度条不显示的根本原因很重要
If you want a progress meter for HTTP POST or PUT requests,
you need to redirect the response output to a file,
using shell redirect (>), -o [file] or similar.
这里的所有其他答案都有一个问题,那就是它们要求您将curl的原始输出写入(日志)文件 问题在于,当需要服务器响应时,curl会隐藏进度条/米,然后将其写入标准输出。 因此,基本上您可以将输出重定向到文件以再次显示条形图。但是我们不希望这样,因此
/dev/null
和tee
可以帮助我们:
curl --progress-bar -T "${SOME_LARGE_FILE}" "${UPLOAD_URL}" | tee /dev/null
Curl的输出被传递到tee
,tee将输出写入控制台(我们希望看到进度条和服务器响应)和文件(我们不需要该文件,但在使用/dev/null
时,这并不重要)
请注意,curl开发人员当然不会为了好玩而隐藏进度条。在这种情况下,您可能不会总是看到服务器结果,或者可能只显示几秒钟(因为进度条随后会再次显示),但如果您不关心这一点,那么这个解决方案是很好的。请参阅进度表部分。我怀疑您需要将输出传输到一个文件,尽管我不是正数。注意!获取下载进度信息所需的
tee
命令。如果您不想使用tee
则只需使用grep-v'^uniqueStringNeverHappe即可ns$'
命令。更多信息:或者:/dev/null
这似乎对我不起作用:(编辑:无需担心,问题是我想计算它需要多长时间,所以我使用了时间卷曲--progress bar--verbose…
来阻止显示进度条。在没有时间的情况下运行它是可行的。“如果您想要HTTP POST或PUT请求的进度表,则需要使用shell redirect(>)、-o[file]或类似方法将响应输出重定向到文件。"我想他们只是为了好玩而隐藏它,因为你明确要求使用--进度条。为什么curl--进度条…| tee/dev/null
?在我的情况下curl--进度条…| cat
似乎也能正常工作。@user000001当然,这是公平的更简单。谢谢。:)您也可以简单地使用“tee”,不需要使用/dev/nullthankyou!Omg花了太长时间才弄明白这一点。
curl --progress-bar -T "${SOME_LARGE_FILE}" "${UPLOAD_URL}" | tee /dev/null