Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/fortran/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
cURL:上传时如何显示进度信息?_Curl - Fatal编程技术网

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