Sure, that will work, and there are lots of other options too. The best depends on your particular needs.
The three most suitable protocols to choose from are:
- SSH - great for interactive work where you type commands and look at the output. Overkill for a file transfer script but it includes a simpler protocol called SFTP which is more suitable. Very well supported and easy to setup outside of Windows. Bit trickier on Windows.
- FTP - specifically designed for file transfer over a network. Very well supported and easy to setup outside of Windows. Bit trickier on Windows.
- SMB - specifically designed to share files with Windows. Native support on Windows and not too bad elsewhere.
Then, given these are all Client-Server protocols, you have two directions to chose from:
- Windows server, Pi client - means you need to install and configure a server on Windows, which is usually a bit trickier. But means all the action initiation (the script) can happen on the Pi.
- Pi server, Windows client - the Pi already has the servers, so means the client install/config is easier on Windows. But means you need to initiate the action on the Windows machine, which you may not want to do.
Finally, you need the script. Assuming the Pi is the client, there's really no need for Python. But you can use it if you like. There are two main options:
- Wrap the built-in Pi's clients (eg. ssh, sftp, ftp, samba) in your favourite scripting language.
- Use a library written for your favourite scripting language (eg. for Python: pysftp, paramiko, ftplib, pysmb)
Depending on your particular requirements, option 1 is probably the easiest if you're running a native script on the Pi and option 2 if you want to use Python. Here's what it might look like as a native
expect -c 'spawn sftp firstname.lastname@example.org;
expect "*Password: ";
send "cd /Users/user \r";
send "get file.txt \r";
send "bye \r"'
or as a Python script, using pysftp:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
# Make connection to sFTP
cnopts = cnopts
) as sftp:
print(file) ## None
Plenty of options to streamline this depending on your needs. See how you go and feel free to ask a more specific question.