Download
Download a file from the target to the Apfell server
What does it mean to download a file?
This section is specifically for downloading a file from the agent to the Apfell server. Because these can be very large files that you task to download, a bit of processing needs to happen: the file needs to be chunked and routed through the agents.
In general, there's a few steps that happen for this process:
The operator issues a task to download a file, such as
download file.txt
This gets sent down to the agent in tasking, the agent locates the file, and determines it has the ability to read it. Now it needs to send the data back
The agent first gets the full path of the file so that it can return that data. That's a quality of live requirement so that operators don't need to supply the full path when specifying files, but so that Apfell can still properly track all files, especially ones that have the same name.
The agent then sends an initial message to the Apfell server indicating that it has a file to send. The agent specifies how many chunks it'll take, and which task this is for.
The Apfell server then registers that file in the database so it can be tracked. This results in a file UUID. The Apfell server sends back this UUID so that the agent and Apfell can make sure they're talking about the same file for the actual transfer.
The agent then starts chunking up the data and sending it chunk by chunk. Each message will have chunk_size amount of data base64 encoded, the file UUID from step 5, and which chunk number is being sent.
The Apfell server responds back with a successful acknowledgement that it received each chunk
It's not an extremely complex process, but it does require a bit more back-and-forth than a fire-and-forget style. This process allows Apfell to track how many chunks it'll take to download a file and how many have been downloaded so far. The rest of this page will walk through those steps with more concrete code examples.
Example (agent response pt. 1):
When an agent is ready to transfer a file from agent to Apfell, it first needs to get the full_path
of the file and determine how many chunks it'll take to transfer the file. It then creates the following structure:
This message is what's sent as an Action: post_response message.
Apfell will respond with a file_id:
Example (agent response pt. 2-n):
The agent sends back each chunk sequentially and calls out the file_id its referring to along with the actual chunked data. The size of the chunks isn't tracked by Apfell right now, so make sure to send them in order.
For each chunk, Apfell will respond with a success message if all went well:
Once all of the chunks have arrived, the file will be downloadable from the Apfell server.
Last updated