由于ftpput每次只能传输单个文件,不支持文件夹传输,所以用tar打包处理。
@REM #########################################################################
@REM # File Name: adb_pushfileto_qnx.bat
@REM # Author: Panda Young
@REM # Version: 1.1.02
@REM # Created Time: 2023年08月08日 星期二 17时47分20秒
@REM #########################################################################
@echo off
setlocal enabledelayedexpansion
color 02
for /f %%i in ('adb shell "getprop dev.bootcomplete"') do set BOOTSTATUS=%%i
if NOT "%BOOTSTATUS%" == "1" (
color 04
echo Android device is not ready!
pause
color 07
exit /b
)
adb root
adb remount
adb shell "mount -o rw,remount /"
set qnx_host_ip=192.168.1.1
set qnx_target_path=/sound_a/
set android_tmp_path=/data/local/tmp/
set tar_path=tar.exe
set BUSYBOX_PATH=busybox
goto :get_input
:check_busybox
for /f %%i in ('adb shell "find / -name busybox" 2^>nul') do set BUSYBOX_PATH=%%i
if "%BUSYBOX_PATH%" == "" (
color 04
echo Not found busybox in the device!
pause
color 07
exit /b
)
:get_input
set /p put_file=Enter the file path to be pushed:
if NOT exist %put_file% (
color 04
echo Not found the file or directory! Please check the path.
pause
color 07
exit /b
)
for %%I in (%put_file%) do (
set target_file_name=%%~nxI
set win_path=%%~dpI
)
if exist "%put_file%\.\" (
set IS_DIR=1
set file_suffix=.tar.gz
set archive_file_name=%target_file_name%!file_suffix!
%tar_path% -zcvf %win_path%!archive_file_name! -C %win_path% %target_file_name%
set target_file_name=!archive_file_name!
adb push %win_path%!target_file_name! %android_tmp_path%
) else (
adb push %put_file% %android_tmp_path%
)
if errorlevel 1 (
color 04
echo Push file to Android device failed!
pause
color 07
exit /b
) else (
echo Push file to Android device successfully!
)
adb shell "%BUSYBOX_PATH% ftpput -u root %qnx_host_ip% %qnx_target_path%%target_file_name% %android_tmp_path%%target_file_name%"
if errorlevel 1 (
color 04
echo Push file to QNX device failed!
pause
) else (
if !IS_DIR!==1 (
echo Push file to QNX device successfully! You can use 'tar -xvf' unpack the file.
) else (
echo Push file to QNX device successfully!
)
)
adb shell "rm %android_tmp_path%%target_file_name%"
if errorlevel 1 (
color 04
echo Delete the temporary file failed!
pause
color 07
exit /b
) else (
echo Delete temporary file in Android successfully!
)
if !IS_DIR!==1 (
del /Q /S /F %win_path%!target_file_name!
if errorlevel 1 (
color 04
echo Delete the temporary file failed!
pause
color 07
exit /b
) else (
echo Delete temporary file in the host successfully!
)
)
color 07
exit /b