Transferring Files
WSO2 IoT Server enables you to upload and download files from Android devices. You need to set up a shared location to manage the files that are sent to the device and the files that are sent from the device to WSO2 IoT Server. The server sends an operation to the device to send the requested file to the defined shared location. Similarly, if a file needs to be sent to the device, the server sends an operation to the device to get the file from the shared location.
Let's take a look at how it works:
Before you begin
- Make sure to have an Android device enrolled. For more information, see Android.
- Set up a shared location to manage the files that need to be sent to the device and the files that are downloaded from the device. The shared location can have the HTTP, FTP, and SFTP transfer protocols.
Uploading files to the device
Follow the steps below to upload a file to your Android device:
- Access the device management console at
https://<IOTS_HTTPS_HOST>:9443/devicemgt
and sign in as an administrator. The default username isadmin
and the default password isadmin
. - Click View under the DEVICES tile.
- Click the device thumbnail and navigate to the device details page.
- Click File Transfer.
- Select the To device option.
- Enter the details to upload a file to the device:
- Select the preferred transfer protocol, such as HTTP, FTP, or SFTP.
- Enter the shared location where the file is stored in one of the following formats:
- For HTTP:
<HTTP_URL>
- For FTP:
FTP://<USER_NAME>@<HOST_NAME>/<FOLDER_PATH>/<FILE_NAME>
- For SFTP:
SFTP://<USER_NAME>@<HOTS_NAME>/<FOLDER_PATH>/<FILE_NAME>
- For HTTP:
- Optionally, enter the location on the device to save the file. It is recommended to provide the location.
- The file path needs to be in the following format:
/<DIRECTORY>/<DIRECTORY>
. For example,/sdcard/Donwload/
. - If the location is not defined, the file is saved to the download directory of the device. On some devices, the files are saved in the file explorer's download directory.
- The file path needs to be in the following format:
Optionally select Authentication required if your shared location is secured using credentials, and enter the username and password for a secure transfer.
If you are using the FTP or SFTP protocols to transfer files and if the username is part of the file URL the Username field is automatically updated using the data from the File URL field.
Example:
It is optional to enter the password. Certain FTP accounts do not require passwords for authentication. In such scenarios, you can leave the password field empty.
Click Send to Device.
You can see the FILE_UPLOAD_TO_THE_DEVICE entry immediately changing to the PENDING state in the Operations Log. After the file is successfully uploaded to the device, the FILE_UPLOAD_TO_THE_DEVICE entry changes to the COMPLETED state.If the file size is large, it takes a few minutes for the file to download to the device based on your network condition.
Example: Successfully completing the operation:
Downloading files from the device
Follow the steps below to download a file from your Android device:
- Click File Transfer.
- Select the From device option.
- Enter the details to download a file from the device:
- Select the preferred transfer protocol, such as HTTP, FTP, or SFTP.
- Enter the shared location path where the file needs to be saved to:
- For HTTP:
<HTTP_URL>
- For FTP:
FTP://<USER_NAME>@<HOST_NAME>/<FOLDER_PATH>
- For SFTP:
SFTP://<USER_NAME>@<HOTS_NAME>/<FOLDER_PATH>
- For HTTP:
- Enter the exact location of the file in the device that needs to be sent to the shared location. If the file path is wrong, the operation is terminated.
The file path needs to be in the following format:/<DIRECTORY>/<DIRECTORY>/<FILE_NAME>
. For example,/sdcard/Donwload/fileName.pdf
. Optionally, select Authentication required if your shared location is secured using credentials, and enter the username and password for a secure transfer.
If you are using the FTP or SFTP protocols to transfer files and if the username is part of the file URL the Username field is automatically updated using the data from the File URL field.
Example:
It is optional to enter the password. Certain FTP accounts do not require passwords for authentication. In such scenarios, you can leave the password field empty.
- Click Send to Device.
A notification is sent to the device asking the device to share the file with WSO2 IoT Server. The device owner needs to Allow this request. Once allowed, the file is sent to the shared location.
You can see the FILE_DOWNLOAD_TO_THE_DEVICE entry immediately changing to the PENDING state in the Operations Log. Once the file is successfully sent to the defined shared location the FILE_DOWNLOAD_TO_THE_DEVICE entry changes to the COMPLETED state.If the file size is large, it takes a few minutes for the file to download to the shared location based on your network condition.
Initially, the file is not there in the shared location you defined. Once the operation is completed you see the file you sent from the device downloaded to the directory.
Failing to transfer files
If you enter the wrong username and password for the shared location credentials, enter an incorrect file path, or if you don't allow the device to share the file when the notification is sent to the device, the file transfer operation is terminated. This is indicated in the Operations Log as an ERROR.
Example: The Operations Log when the device owner cancels the file share request.