SCP script with Python

On 2017 Feb 13 04:04:46, you wrote to All:

JL> I have an SCP script that auto completes just fine from the terminal JL> window in Pi. When I use either subprocess or os to try and have it JL> run under Python it does not do the file transfer from Pi to my Ubuntu JL> machine. What am I doing wrong? Here is the script:

JL> from subprocess import call JL> cmd='scp -i id_rsa sample.txt jack@192.168.1.103 /home/jack/pi_data' JL> call (cmd.split ())

how are you feeding it the password? the password is being requested, isn't it?

)\/(ark

Always Mount a Scratch Monkey Do you manage your own servers? If you are not running an IDS/IPS yer doin' it wrong... ... Well! I'm impressed.

Reply to
mark lewis
Loading thread data ...

I have an SCP script that auto completes just fine from the terminal window in Pi. When I use either subprocess or os to try and have it run under Py thon it does not do the file transfer from Pi to my Ubuntu machine. What a m I doing wrong? Here is the script:

from subprocess import call cmd='scp -i id_rsa sample.txt jack@192.168.1.103 /home/jack/pi_data' call (cmd.split ())

Thank you

Reply to
Jack Lobingier

Wrong scp syntax, should be jack@192.168.1.103:/home/jack/pi_data

--
http://www.greenend.org.uk/rjk/
Reply to
Richard Kettlewell

Sorry, mistyped, the colon was in there, and it does work ok under the terminal window.

Reply to
Jack Lobingier

Sorry, I mistyped the script. I did use the colon, and it works ok under the terminal window.

Reply to
Jack Lobingier

Can you be more specific about the environment - are you running the Python program from a terminal window, or in some other way (e.g. cron job)? What authentication is scp using?

Reply to
Roger Bell_West

OK, please copy+paste the actual script into a posting, plus a transcript showing it running. It?s not practical to debug something without being able to see it.

--
http://www.greenend.org.uk/rjk/
Reply to
Richard Kettlewell

My guess is it is not finding the id_rsa file because the script isn't picking up the current working directory. Try with the full path to the file. (and the full path to scp too maybe)

Theo

Reply to
Theo

I went through the key-gen process to generate a private and public key. That is what the "id_rsa" is part of the command is looking at, so yes, it does auto complete without manual password entry.

Reply to
Jack Lobingier

I'm guessing, but since it works from the command line but not from a non-interactive mode, you might try this: scp -i ~/.ssh/id_rsa

--
Consulting Minister for Consultants, DNRC 
I can please only one person per day. Today is not your day. Tomorrow 
 Click to see the full signature
Reply to
I R A Darth Aggie

Yes, that's what I thought: use the complete path to the id file (maybe even don't use "~", to avoid all potential ambiguity).

Reply to
A. Dumas

JL> from subprocess import call JL> cmd='scp -i id_rsa sample.txt jack@192.168.1.103 /home/jack/pi_data' JL> call (cmd.split ())

are you using ssh keys for authentication?

I've got some python working to transfer data. here is a command. use the subprocess.

subprocess.call("scp -q %s user@host:/path/file" %(inputfile, s), shell = True)

you will need to make sure you have keys on the target system basically the host.

Reply to
Grant Weasner

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.