简体   繁体   中英

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, ...).

But there is a way to monitor progress independently on what is progressing: pv (pipe viewer) .

This tool has the sole purpose of generating monitoring information. It can be used in a way much similar to cat . You either use it to "lift" a file to pv 's stdout....

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. I used 2 Gigabyte expected size here ( -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). Together they make for a nice mnemonic.

Other nice options:

  • -L , which can be used to limit the maximum rate in the pipe (throttle).
  • -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).

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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