Question
Is there a method to transfer accounts using WHM API calls?
Answer
The recommended method to transfer accounts to your cPanel server is using the WHM: Transfer Tool or WHM: Transfer or Restore a cPanel Account feature. It takes into account the different combinations of options. Using the API to transfer has plenty of options to consider.
Review the WHM API documentation pages below:
- Create Remote User Transfer Session
- Enqueue Transfer Item
- Start Transfer Session
- Get Transfer Session State
The API calls will be done in order.
We will use the following information in our example, showing output:
Remote server: 10.2.32.216
Account to transfer: cptest
The 'create_remote_user_transfer_session' call will setup the connection. The output will provide the transfer_session_id for the rest of the API calls:
# whmapi1 create_remote_user_transfer_session host=10.2.32.216 password=cpanel1 unrestricted_restore=1
---
data:
transfer_session_id: 10232216noroo202008261343593rYxE7bWu
metadata:
command: create_remote_user_transfer_session
reason: OK
result: 1
version: 1
Then, the 'enqueue_transfer_item' gives the Transfer the options you will use during the Transfer.
# whmapi1 enqueue_transfer_item module=AccountRemoteRoot user=cptest localuser=cptest transfer_session_id=10232216noroo202008261343593rYxE7bWu
---
metadata:
command: enqueue_transfer_item
reason: OK
result: 1
version: 1
After, the 'start_transfer_session' call will start the Transfer itself:
# whmapi1 start_transfer_session transfer_session_id=10232216noroo202008261343593rYxE7bWu
---
data:
pid: 44380
metadata:
command: start_transfer_session
reason: OK
result: 1
version: 1
The Transfer should now be working. You can view its progress in two ways.
From the 'get_transfer_session_state' API call:
# whmapi1 get_transfer_session_state transfer_session_id=10232216noroo202008261343593rYxE7bWu
---
data:
state_name: COMPLETED
metadata:
command: get_transfer_session_state
reason: OK
result: 1
version: 1
Or from a WHM script:
# /usr/local/cpanel/bin/view_transfer 10232216noroo202008261343593rYxE7bWu
The transfer for session ID “10232216noroo202008261343593rYxE7bWu” is complete.
[ 44380][MASTER ]: Start Session
[ 44380][MASTER ]: Version: 2.3
[ 44380][MASTER ]: Queue “TRANSFER” items: 1
[ 44380][MASTER ]: Queue “RESTORE” items: 1
[ 44380][MASTER ]: Remote Host: 10.2.32.216
[ 44381][TRANSFER:1]: Starting “Account”: cptest
[ 44381][TRANSFER:1][A:cptest ]: Progress: 0% (2020-08-26 08:45:08 -0500)
[ 44381][TRANSFER:1][A:cptest ]: Starting “TRANSFER” for “Account” “cptest”.
[ 44381][TRANSFER:1][A:cptest ]: Copy Destination: /home
[ 44381][TRANSFER:1][A:cptest ]: Progress: 100% (2020-08-26 08:45:08 -0500)
[ 44381][TRANSFER:1]: Progress: 100% (2020-08-26 08:45:08 -0500)
[ 44381][RESTORE:1 ][A:cptest ]: Starting “RESTORE” for “Account” “cptest”.
[ 44381][RESTORE:1 ]: Progress: 100% (2020-08-26 08:45:08 -0500)
[ 44381][TRANSFER:1]: Child Complete
[ 44382][RESTORE:1 ]: Child Complete
[ 44380][MASTER ]: Session Complete
You can also view the Transfer in the WHM interface:
Navigate to WHM: Home » Transfers »Review Transfers and Restores
Find transfer_session_id, and click 'Review' on the right-hand side.
It will display the transfer results in the WHM interface.