I'm very new to the RPi world. I have a Raspberry Pi Zero and I want it to send a file via SCP to my Windows computer.

I can enter my RPi via SSH from my PC and I can extract files from it and move them to my PC via SCP.

I've also created a program in Python using Paramiko to extract files from RPi. The program has to be executed in my PC.

import paramiko

#Connect my PC to my RPi via SSH
ssh_client = paramiko.SSHClient()
ssh_client.connect("", port = 0, username = "username",password="password")

#Move file from RPi to my PC

But what I want now is (using Python and Paramiko if possible) to move a file from my RPi to my PC but connecting my RPi to my PC instead of my PC to the RPi. I could access my RPi from my PC using SSH and then execute this program inside RPi and have my RPi connect to my PC and transfer some files automatically.

How can I do this? I've read that I have to generate a SSH server in my computer. What does that mean? Having a link between my PC and my RPi is not enought? If so, how do I create that server on my Windows machine? and what commands should the python script inside my RPi should have as to call my PC to send files to it instead of me from the PC to call the RPi and transfer those same files to my PC?

  • just so you know, this is not pi specific so might get flagged. – scitronboy Mar 21 '18 at 22:10
  • Take a look at mobaXterm mobaxterm.mobatek.net , which has a builtin SFTP browser, allowing you to just drag&drop files both directions while in your usual SSH session. – mystery Mar 22 '18 at 9:41
  • A reasonable alternative may be to install Samba on your Pi, and set up a Windows file share. You can then mount that share on your Pi, and access the Windows share as if it's a local directory. E.g. you can use cp /path/to/file/on/Pi /mnt/WindowsShare/SubDir. – MSalters Mar 23 '18 at 15:28

I'd suggest reading up on SSH a little more to get more familiar, so maybe take a look at the Wikipedia article https://en.m.wikipedia.org/wiki/Secure_Shell or Google it and check out promising articles.

However in essence the server/client thing is really just the side of the connection and role that each computer has. In answer to your question "Having a link ... is not enough?" - you need one side to be listening, so it can receive connections. In the scenario you're looking at here (have the process run from the RPi and send a file to the PC) the PC would indeed be the server - but don't be put off!

For a Windows PC, then you can find details of the software needed with Google (again), but what seems to be a reasonable guide is here on the WinSCP site: https://winscp.net/eng/docs/guide_windows_openssh_server

Once you've done that, the script will be similar to what you have, but you'd need to use a put instead of a get (since from the perspective of the script things are now the other way round):

put(localpath, remotepath, callback=None, confirm=True)

Full details are here: http://docs.paramiko.org/en/2.4/api/sftp.html#paramiko.sftp_client.SFTPClient.put

  • The OP did include the word Windows in reference to his PC OS. – L. D. James Mar 22 '18 at 3:05
  • My mistake, not sure how I missed that. Will edit my comment. Thanks! – Neil Mar 23 '18 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.