Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to transfer a file to ssh server in an ssh-connection made by paramiko?

I am using Python's paramiko packet to keep an ssh-connection with an server :

s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect("xxx.xxx.xxx.xxx",22,username=xxx,password='',timeout=4)

I want to use this ssh-connection to transfer a file to ssh server, how can i do?

Just like use scp a-file [email protected]:filepath command?

like image 230
Coaku Avatar asked Jul 16 '12 07:07

Coaku


People also ask

How do I connect to a paramiko remote server?

A Paramiko SSH Example: Connect to Your Server Using a Password. This section shows you how to authenticate to a remote server with a username and password. To begin, create a new file named first_experiment.py and add the contents of the example file. Ensure that you update the file with your own Linode's details.

Does paramiko use OpenSSH?

Paramiko does not itself leverage OpenSSH-style config file directives, but it does implement a parser for the format, which users can honor themselves (and is used by higher-level libraries, such as Fabric).

How do I move a file from one server to another in python?

The easiest way to copy files from one server to another over ssh is to use the scp command. For calling scp you'd need the subprocess module.


1 Answers

Try this:

s = paramiko.SSHClient()
s.set_missing_host_key_policy(paramiko.AutoAddPolicy())
s.connect("xxx.xxx.xxx.xxx",22,username=xxx,password='',timeout=4)

sftp = s.open_sftp()
sftp.put('/home/me/file.ext', '/remote/home/file.ext')
like image 115
Tisho Avatar answered Sep 22 '22 14:09

Tisho