Yes, there is.
- Download the remote file temporarily to the local computer where your Python code is located with SCP.
- Modify it.
- Upload the modified file to the remote with SCP.
Step 1: Download the remote file
scp -i ~/.ssh/the-ssh-key remoteusername@remote-ip:/remote-location/remote-file.txt /local-location/local-file.txt
Step 2: After modifying the file, upload it to the remote.
scp /local-location/local-file.txt -i ~/.ssh/the-ssh-key remoteusername@remote-ip:/remote-location/remote-file.txt
Then you can delete the temporary local file if you want.
If you want to create a new file on the remote:
Create the file in the local computer where your Python is located.
Create the file.
Upload the created file to the remote with SCP.
scp /local-location/local-file.txt -i ~/.ssh/the-ssh-key remoteusername@remote-ip:/remote-location/remote-file.txt
If you want to access the remote with a password instead of an ssh key or to learn more about the usage of SCP, you can follow the instructions here:
https://linuxize.com/post/how-to-use-scp-command-to-securely-transfer-files/
ALTERNATIVE METHOD
Instead of using a pure SCP command, you can prefer subprocess in python.
import subprocess
subprocess.run(["scp", FILE, "USER@SERVER:PATH"])
#e.g. subprocess.run(["scp", "foo.bar", "joe@srvr.net:/path/to/foo.bar"])
Source: https://stackoverflow.com/a/68365/15529570