-1

I am looking to automate file retrieval from a python program that gets a file from my Raspberry Pi and returns it to my local PC. I have tried SSH, FTP & SCP but can't get any to work and run into connection problems in my Python program. Any one have a quick code snippet. below is the code I think should work but getting an error

  • From PI: Raspberry PI Zero W
  • Receiving PC: Windows 10 running a pycharm python program

-IDE: Pycharm

NOTE: Connected to same network, ssh, putty, cmd line SCP, remote desktop work to PI but I can't do the same by just running a python program to get a file.

Filename: testfile.jpg Pi: Directory. /home/pi/testfile.jpg

Open to any method to retrieve file as long as it can do it automagically?

Ideas?

Thank you!


Code failing with Cryptography deprecation error

Code won't make simple connection - feel its on my local pC?

from paramiko import SSHClient
from scp import SCPClient

ssh = SSHClient()
ssh.Connect(ipadd.re.ss)

CAN'T GET PAST HERE ERROR BELOW

Error: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding. m.add_string(self.Q_C.public_numbers().encode_point())

smac89
  • 39,374
  • 15
  • 132
  • 179
Sam
  • 9
  • 3
  • I think reading over this question would be helpful to you. https://stackoverflow.com/questions/3586106/perform-commands-over-ssh-with-python – Bbb Jan 24 '19 at 19:12
  • If command-line SFTP or SCP works, show us an equivalent Python code that you have tried and that does not work. Without that, all we can do is point you to a generic code for SFTP/SCP. – Martin Prikryl Jan 24 '19 at 21:46
  • The SCP works but not sure how to add in password which is a second prompt. Can you add this into your scp connect? – Sam Jan 24 '19 at 22:09
  • If you've written some code that doesn't work, you should include that in your question and explain what happens when you run it. – Kenster Jan 24 '19 at 23:31
  • Thanks! first post. Added the code and error with the approach that i think should work – Sam Jan 25 '19 at 00:53
  • It looks like your immediate problem is the `CryptographyDeprecationWarning` not the password, right? Show us [Paramiko log file](https://stackoverflow.com/q/27587716/850848). – Martin Prikryl Jan 25 '19 at 07:22

1 Answers1

-1

Have you heard of Paramiko? It's an SSH client for Python.

You could do something like:

client.connect(...)
i, o, e = client.exec_command('cat /home/pi/testfile.jpg')
with open('testfile.jpg', 'wb') as f:
    for line in o:
        # these are lines in the file.
        f.write(line)
blueteeth
  • 3,330
  • 1
  • 13
  • 23
  • You are reading a *binary* file by *lines*! – Martin Prikryl Jan 24 '19 at 21:47
  • I did try this but get an error on connect: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding. m.add_string(self.Q_C.public_numbers().encode_point()) – Sam Jan 24 '19 at 22:06
  • @MartinPrikryl On my computer I can run `cat testfile.jpg > testfile_copy.jpg`. I can do a similar thing in Python. https://pastebin.com/EHUnz4NN What relevance is it that it's a binary file? Sure it's not an ideal way to do things, but it does work. – blueteeth Jan 25 '19 at 18:26
  • I was not questioning your use of `cat`. I was questioning your `for` loop. It's not what `cat testfile.jpg > testfile_copy.jpg` does. – Martin Prikryl Jan 25 '19 at 18:33