blob: 1648c75700128d408f60b398e4d38711eab90db4 [file] [log] [blame]
#!/bin/bash
# Copyright 2017 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
### copy a file to/from a target device
## usage: fx cp [--to-target|--to-host] SRC... DST
##
## Copies a file from the host to the target device, or vice versa.
##
## --to-target: copy file SRC from host to DST on the target
## --to-host: copy file SRC from target to DST on the host
##
## The default is to copy files to the target.
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"/lib/vars.sh || exit $?
set -e
to_target=true
if [[ $# -gt 2 ]]; then
case "$1" in
--to-target)
to_target=true
shift
;;
--to-host)
to_target=false
shift
;;
--help)
fx-command-help
exit 1
esac
fi
if [[ $# -lt 2 ]]; then
fx-command-help
exit 1
fi
args=( "$@" )
nargs=${#args[@]}
dst=${args[$nargs-1]}
srcs=( "${args[@]:0:$nargs-1}" )
host="$(get-fuchsia-device-addr)"
if [[ "${to_target}" = "true" ]]; then
(
for src in "${srcs[@]}"; do
echo "put \"${src}\" \"${dst}\""
done
) | fx-command-run sftp -q -b - "[${host}]" > /dev/null
else
(
for src in "${srcs[@]}"; do
echo "get \"${src}\" \"${dst}\""
done
) | fx-command-run sftp -q -b - "[${host}]" > /dev/null
fi