Uploading bin to Arduino Mega 2560 from arduino nano while SD card reader connected to mega and nano and Ethernet SPI module connected Mega only

Hello all, I need a project for that Programming Arduino Mega 2560 from arduino nano while SD card reader connected Mega and nano, and Ethernet SPI module connected only to Mega . Mega will download bin file from /server and store it in sd card. and send signal to nano and deactivate ethernet and sdcard with mega. but activate SD card with nano and program mega via SPI. is it possible? and how connections should be. I am newbie and I need help. thanks.

Mega can update itself with SD boot or with modified Optiboot and my ArduinoOTA library

https://github.com/JAndrassy/ArduinoOTA/blob/master/README.md#atmega-support

You will need to connect the SD card module and Ethernet to the Mega. And the Nano will program the mega through SPI.

Thank you for support. What is the default CS pins for ethernet and SD card in your library? @juraj

If ethernet and SD on the SPI bus, you need some way to keep the CS pins HIGH while the Mega is programmed.

I suggest 10K resistors from 5v to the CS pins on the ethernet and SD. That should keep them disabled while the Mega is programmed. Otherwise you are likely to encounter bus contention on the SPI bus.

Just a thought.

What is the default CS pins for ethernet and SD card in your library?

these libraries are initialized by the sketch, not by the ArduinoOTA library.
or if you use some SD bootloader then you have to look what CS pin it uses.