Is it possible to get files list that were downloaded using scp -r
?
Example:
$ scp -r $USERNAME@HOSTNAME:~/backups/ .
3.tar 100% 5 0.0KB/s 00:00
2.tar 100% 5 0.0KB/s 00:00
1.tar 100% 4 0.0KB/s 00:00
Expected result:
3.tar
2.tar
1.tar
scp -v -r yourdir orczhou@targethost:/home/orczhou/ \
2> >(awk '{if($0 ~ "Sending file modes:")print $6}')
with -v "Sending file modes: C0644 7864 a.sql" should be ouput to stderr
use 'awk' to pick out the file list
The output that scp
generates does not seem to come out on any of the standard streams (stdout or stderr), so capturing it directly may be difficult. One way you could do this would be to make scp
output verbose information (by using the -v
switch) and then capture and process this information. The verbose information is output on stderr, so you will need to capture it using the 2>
redirection operator.
For example, to capture the verbose output do:
scp -rv $USERNAME@HOSTNAME:~/backups/ . 2> scp.output
Then you will be able to filter this output with something like this:
awk '/Sending file/ {print $NF}' scp.output
The awk
command simply prints the last word on the relevant line. If you have spaces in your filenames then you may need to come up with a more robust filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With