简体   繁体   English

获取正在上传的文件的进度 - unix

[英]get progress of a file being uploaded - unix

i have a requirement to monitor the progress of a file being uploaded using script.我需要监视使用脚本上传的文件的进度。 In putty(software) we can view the Percentage Uplaod, Bytes transferred , Upload Speed and ETA in the right hand side.在腻子(软件)中,我们可以在右侧查看上传百分比、传输的字节数、上传速度和预计到达时间。 I want to develop a similar functionality.我想开发一个类似的功能。 Is there any way to achieve this?有没有办法实现这一目标?

Your question is lacking any information of how your file is transferred.你的问题是缺乏的文件是如何传输的任何信息。 Most clients have some way to display progress, but that is depending on the individual client used (scp, sftp, ncftp, ...).大多数客户端都有某种方式来显示进度,但这取决于所使用的单个客户端(scp、sftp、ncftp 等)。

But there is a way to monitor progress independently on what is progressing: pv (pipe viewer) .但是,有一种方法来监测进展情况独立地在什么进展: pv (管浏览器)

This tool has the sole purpose of generating monitoring information.该工具的唯一目的是生成监控信息。 It can be used in a way much similar to cat .它的使用方式与cat非常相似。 You either use it to "lift" a file to pv 's stdout....您要么使用它来将文件“提升”到pv的标准输出....

pv -petar <file> | ...

...or you use it in the middle of a pipe -- but you need to manually provide the "expected size" in order to get a proper progress bar, since pv cannot determine the size of the transfer beforehand. ...或者您在管道中间使用它——但是您需要手动提供“预期大小”以获得正确的进度条,因为pv无法事先确定传输的大小。 I used 2 Gigabyte expected size here ( -s 2G )...我在这里使用了 2 GB 的预期大小( -s 2G )...

cat <file> | pv -petar -s 2G | ...

The options used are -p (progress bar), -e (ETA), -t (elapsed time), -a (average rate), and -r (current rate).使用的选项是-p (进度条)、- -e (ETA)、- -t (经过时间)、 -a (平均速率)和-r (当前速率)。 Together they make for a nice mnemonic.它们一起构成了一个很好的助记符。

Other nice options:其他不错的选择:

  • -L , which can be used to limit the maximum rate in the pipe (throttle). -L ,可用于限制管道中的最大速率(节流)。
  • -W , to make pv wait until data is actually transferred before showing a progress bar (eg if the tool you are piping the data to will require a password first). -W ,让pv在显示进度条之前等待数据实际传输(例如,如果您将数据传输到的工具首先需要密码)。

This is most likely not what you're looking for (since chances are the transfer client you're using has its own options for showing progress) , but it's the one tool I know that could work for virtually any kind of data transfer, and it might help others visiting this question in the future.这很可能不是您要找的(因为您使用的传输客户端可能有自己的显示进度选项) ,但这是我所知道的一种工具,几乎可以用于任何类型的数据传输,并且它可能会帮助其他人在未来访问这个问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM