高通 Linux 蓝牙指南(十三)

蓝牙中的文件传输协议

FTP 定义了在两个蓝牙之间交换文件的要求 设备。

要执行 Bluetooth FTP 功能,您必须首先完成以下步骤 程序。

设置设备以实现蓝牙 FTP 功能

先决条件

  • 启用 SSH 以访问您的主机设备。

  • 确保 DUT 和远程设备支持 BlueZ 堆栈。一台设备 充当服务器,另一个设备充当客户端。

    注意测试或验证 FTP server 函数,则不需要测试应用程序。FTP 函数包括 通过客户端连接执行。

  • 将 DUT 与远程设备配对。

  • 将 DUT 和远程设备放在蓝牙附近。

程序

  1. 使用以下命令在命令提示符中运行 SSH:

    ssh root@<device_IP_address>
    

    如果设备的 IP 地址为 ,则运行 以下命令:10.92.160.222

    ssh root@10.92.160.222
    
  2. 输入以下密码连接到 SSH:

    oelinux123
    
  3. 通过运行以下命令打开 Bluetooth 测试应用程序:要查看 OBEX 函数,请运行以下命令:

    obexctl
    
    help
    

    这 command 提供 obexctl 的主菜单。

    示例输出

    sh-5.1# obexctl
    \[NEW\] Client /org/bluez/obex
    \[obex\]# help
    Menu main:
    Available commands:
    -------------------
    connect <dev> \[uuid\] \[channel\]                    Connect session
    disconnect \[session\]                              Disconnect session
    list                                              List available sessions
    show \[session\]                                    Session information
    select <session>                                  Select default session
    info <object>                                     Object information
    cancel <transfer>                                 Cancel transfer
    suspend <transfer>                                Suspend transfer
    resume <transfer>                                 Resume transfer
    send <file>                                       Send file
    pull <file>                                       Pull Vobject & stores in file
    cd <path>                                         Change current folder
    ls <options>                                      List current folder
    cp <source file> <destination file>               Copy source file to destination file
    mv <source file> <destination file>               Move source file to destination file
    rm <file>                                         Delete file
    mkdir <folder>                                    Create folder
    version                                           Display version
    quit                                              Quit program
    exit                                              Quit program
    help                                              Display help about this program
    export                                            Print environment variables
    \[obex\]#
    
  1. 通过从菜单运行以下命令连接到远程设备:obexctl

    connect <bt_address> <profile_name>
    

    参数

    • <bt_address>是遥控器的 Bluetooth 地址 装置。
    • <profile_name>是。ftp

    要使用 连接到远程设备,请运行以下命令:<bt_address>``E8:48:B8:C8:20:00

    connect E8:48:B8:C8:20:00 ftp
    

    示例输出


    \[E8:48:B8:C8:20:00\]# connect E8:48:B8:C8:20:00 ftp
    Attempting to connect to E8:48:B8:C8:20:00
    \[NEW\] Session /org/bluez/obex/client/session7
    \[NEW\] FileTransfer /org/bluez/obex/client/session7
    Connection successful

执行蓝牙 FTP 客户端功能

您可以使用 obexctl 的主菜单。

注意测试或验证 FTP 服务器 函数,则不需要测试应用程序。FTP 功能通过以下方式执行 客户端连接。

创建文件夹

要在远程设备上创建文件夹,请从菜单中运行以下命令:obexctl

mkdir <folder_name>

您可以在服务器上的 /var/bluetooth 目录中验证文件夹的创建。

参数

<folder_name>是新的文件夹名称。

要创建名为 new_dir 的文件夹,请运行以下命令 命令:

mkdir new_dir

示例输出

#mkdir new\_dir
Attempting to CreateFolder
CreateFolder successful

更改当前文件夹

要更改远程设备的当前文件夹,请从菜单中运行以下命令:obexctl

cd <folder_path>

参数

<folder_path>是要切换到的文件夹。

要将当前文件夹更改为 new_dir,请运行以下命令 命令:

cd new_dir

示例输出

#cd new_dir
Attempting to ChangeFolder to new_dir
ChangeFolder successful

获取当前文件夹信息

要获取有关当前文件夹的信息,请从菜单中运行以下命令:obexctl

ls .

示例输出


\# ls .
Attempting to ListFolder
\[NEW\] Transfer /org/bluez/obex/client/session7/transfer4
\[CHG\] Transfer /org/bluez/obex/client/session7/transfer4 Size: 611
\[CHG\] Transfer /org/bluez/obex/client/session7/transfer4 Status: complete
      Type: folder
       Name: My\_folder
       User-perm: RWD
       Group-perm: R
       Other-perm:
       Accessed: 20231214T123503Z
       Modified: 20231214T123502Z
       Created: 20231214T123502Z
       Type: folder
       Name: new\_dir
       User-perm: RWD
       Group-perm: R
       Other-perm:
       Accessed: 20231215T093311Z
       Modified: 20231215T093245Z
       Created: 20231215T093245Z

将文件复制到远程设备

要将本地文件复制到远程设备,请从菜单中运行以下命令:obexctl

cp :<source_file> <destination_file>

参数

  • <source_file>是本地文件。
  • <destination_file>是远程 装置。

要将 Documents/ftp_client.txt 中的本地文件复制到远程设备上的 ftp_client.txt,请运行以下命令 命令:

cp :Documents/ftp_client.txt ftp_client.txt

示例输出

\# cp :Documents/ftp\_client.txt ftp\_client.txt
Attempting to PutFile
\[NEW\] Transfer /org/bluez/obex/client/session7/transfer5
Transfer /org/bluez/obex/client/session7/transfer5
      Status: queued
       Name: ftp\_client.txt
       Size: 10
       Filename: Documents/ftp\_client.txt
       Session: /org/bluez/obex/client/session7
\[CHG\] Transfer /org/bluez/obex/client/session7/transfer5 Status: complete
\[DEL\] Transfer /org/bluez/obex/client/session7/transfer5

从远程设备复制文件

要将文件从远程设备复制到本地目录,请运行以下命令 从菜单中:obexctl

cp <destination_file> :<source_file>

参数

  • <source_file>是远程设备上的文件。
  • <destination_file>是本地 装置。

要将ftp_client_2.txt文件从远程设备复制到 local device 中,运行以下命令:

cp ftp_client_2.txt :ftp_client_2.txt

示例输出

\# cp ftp\_client\_2.txt :ftp\_client\_2.txt
Attempting to GetFile
\[NEW\] Transfer /org/bluez/obex/client/session7/transfer21
Transfer /org/bluez/obex/client/session7/transfer21
       Status: queued
       Name: ftp\_client\_2.txt
       Size: 0
       Filename: ftp\_client\_2.txt
       Session: /org/bluez/obex/client/session7
\[CHG\] Transfer /org/bluez/obex/client/session7/transfer21 Size: 13
\[CHG\] Transfer /org/bluez/obex/client/session7/transfer21 Status: complete
\[DEL\] Transfer /org/bluez/obex/client/session7/transfer21

在远程设备中复制文件

要将文件从某个目录复制到远程设备上的另一个目录,请运行 以下命令:obexctl

cp <source_file> <destination_file>

参数

  • <source_file>是要复制的文件。
  • <destination_file>是目标位置。

要将ftp_client.txt复制到 /new_dir_2/,请运行 以下 命令:

cp ftp_client.txt ../new_dir_2/ftp_client.txt

示例输出

\# cp ftp\_client.txt ../new\_dir\_2/ftp\_client.txt
Attempting to CopyFile
CopyFile successful

移动文件

要在远程设备上将文件从一个文件夹移动到另一个文件夹,请运行以下命令 命令:obexctl

mv <source_file> <destination_file>

参数

  • <source_file>是要移动的文件。
  • <destination_file>是目标位置。

要将ftp_client_2.txt文件移动到 /new_dir_2/,请运行以下命令 命令:

mv ftp_client_2.txt ../new_dir_2/ftp_client_2.txt

示例输出

#mv ftp\_client\_2.txt ../new\_dir\_2/ftp\_client\_2.txt
Attempting to MoveFile
MoveFile successful

删除文件

要删除文件,请从菜单中运行以下命令:obexctl

rm <filename>

参数

<filename>是要删除的文件。

要删除文件,请运行以下命令:ftp_client.txt

rm ftp_client.txt

示例输出

\# rm ftp\_client.txt
Attempting to Delete
Delete successful
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值