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
script:
#!/usr/bin/expect
export PW="your_ssh_password"
expect -c 'spawn sftp your_ssh_username@windows.ip.address;
expect "*Password: ";
send "$env(PW)\r";
expect "sftp>";
send "cd /Users/user \r";
expect "sftp>";
send "get file.txt \r";
expect "sftp>";
send "bye \r"'
or as a Python script, using pysftp:
import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
# Make connection to sFTP
with pysftp.Connection(windows.ip.address,
username=your_ssh_username,
password=your_ssh_password,
cnopts = cnopts
) as sftp:
sftp.get('/Users/user/file.txt', '/local/path/file.txt')
print(file) ## None
sftp.close()
Plenty of options to streamline this depending on your needs. See how you go and feel free to ask a more specific question.