I would like to connect to a remote server, download and extract binary tar file into a specific directory on that host. I am using python 2.6.8
- What would be a simple way to ssh to that server?
I see the below errors on my script to download the tar file and extract it
Traceback (most recent call last): File "./wgetscript.py", line 16, in tar = tarfile.open(file_tmp) File "/usr/lib64/python2.6/tarfile.py", line 1653, in open return func(name, "r", fileobj, **kwargs) File "/usr/lib64/python2.6/tarfile.py", line 1715, in gzopen fileobj = bltn_open(name, mode + "b") TypeError: coercing to Unicode: need string or buffer, tuple found
#!/usr/bin/env python
import os
import tarfile
import urllib
url = 'http://**************/Lintel/Mongodb/mongodb-linux-x86_64-enterprise-suse12-3.2.6.tgz'
fullfilename = os.path.join('/tmp/demo1','file.tgz')
file_tmp = urllib.urlretrieve(url,fullfilename)
print file_tmp
base_name = os.path.basename(url)
print base_name
file_name, file_extension = os.path.splitext(base_name)
print file_name, file_extension
tar = tarfile.open(file_tmp)
nameoffile = os.path.join('/tmp/demo1','file')
tar.extractall(file_name,nameoffile)
tar.close()
tarfile.open(fullfilename)
– Jean-François Fabre