SCP script with Python

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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

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.

Re: SCP script with Python
On Monday, February 13, 2017 at 12:15:14 PM UTC-6, mark lewis wrote:
Quoted text here. Click to load it

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.  

Re: SCP script with Python
Quoted text here. Click to load it

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

--  
http://www.greenend.org.uk/rjk/

Re: SCP script with Python
Sorry, mistyped, the colon was in there, and it does work ok under the terminal window.

Re: SCP script with Python
Quoted text here. Click to load it

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/

Re: SCP script with Python
Sorry, I mistyped the script.  I did use the colon, and it works ok under the terminal window.

Re: SCP script with Python
On 2017-02-13, Jack Lobingier wrote:
Quoted text here. Click to load it

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?

Re: SCP script with Python
Quoted text here. Click to load it

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

Re: SCP script with Python
On Mon, 13 Feb 2017 04:04:47 -0800 (PST),

Quoted text here. Click to load it

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
We've slightly trimmed the long signature. Click to see the full one.
Re: SCP script with Python
On 14/02/2017 19:43, I R A Darth Aggie wrote:
Quoted text here. Click to load it

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


Re: SCP script with Python
 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.  


Site Timeline