views:

658

answers:

5

Hi,

How is it possible to do secure copy using python (windows native install - ActivePython). Unfortunately pexpect module is for unix only and we don't want cygwin locally. I wrote a script that based on pscp.exe win tool - but always stops at first execution becuse of fingerprint host id. and haven't found option to switch this off. the remote hosts are running ssh-server on cygwin (win 2003 servers).

Thanks

A: 

How do you expect to provide the authentication data? The easiest way is to create a key, and make sure it is in the server's list of accepted hosts. That way scp will authenticate using the private/public key pair automatically, and "just work".

This is a handy tutorial on how to go about creating and uploading the key. Of course this assumes you have the necessary admin access to the server.

unwind
+1  A: 

http://pypi.python.org/pypi/ssh4py

SCP example: http://blog.keyphrene.com/keyphrene/index.php/2008/09/18/13-scp

vartec
This is a super easy module, just don't compile for Python 2.6
John Giotta
+2  A: 

paramiko is pretty slick. See this question for some more details.

Nicholas Riley
+1  A: 

Twisted Conch supports ssh and sftp.

nosklo
+2  A: 

I strongly recommend that you use keys rather than passwords. If you use ssh keys properly, you do not need to use expect, as the scp command won't ask for any user input. If you have command line ssh installed, you can make a key like this:

ssh-keygen -t dsa

Then simply follow the instructions provided, and save the key to the default location. If you put a passphrase on it, you'll need to use some sort of ssh agent, either the command line ssh-agent or pagent on windows. You can also create an ssh key with the putty suite's puttygen.

To set up the key for authentication, simply put a copy of id_dsa.pub on the host you want to scp to in the file ~/.ssh/authorized_keys.

Benson