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?
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.
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).
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.
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')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With