I was transferring some files over the network and my macbook pro just fell asleep. I had the "Wake for network traffic" in Preferences>Energy checked. I am using High Sierra. It doesn't sound like Apple not to prevent sleeping while you are conducting an operation. This a bug or a feature?
You can install 3rd part app Caffeine. you can turn it on to prevent your mac from sleeping. Other popular apps are Anti Sleep and Amphetamine. I'm pretty sure all 3 are free. Amphetamine is also available from the App Store. I personally use Caffeine and it works well. It adds a coffee cup icon to menu bar so you can easily turn it on or off.
Caffeine may actually come with newer system upgrades so check your Applications folder.
I am not sure how familiar you are with it, but the terminal command
caffeinate will keep your computer from sleeping. This lets you add it as part of a script, and doesn't rely on third party applications (Caffeine just runs that command anyway, it's not adding any functionality that didn't already exist).
This way, you can activate it when transferring files, either manually or part of some automated workflow (eg. a bash script or with Alfred workflows, etc.)