Reputation: 522
I am copying a set of zli files from a folder to another folder. Now i need to decompress each file in that folder. I am running python using Pycharm from Windows and the folders are in a Linux server. How can i get to the current folder and decompress each file?
from __future__ import with_statement
from fabric.api import *
import ConfigParser, paramiko, shutil, os, glob, zlib
def get_Connection():
config = ConfigParser.RawConfigParser()
config.read('config.cfg')
env.user = config.get('UK_CDN','db.user_name' )
env.password = config.get('UK_CDN','db.password' )
host = config.get('UK_CDN','db.ip' )
with settings(hide('warnings', 'running', 'stdout', 'stderr'), warn_only=True, host_string=host):
paramiko.util.log_to_file('ENC_Analysis.log')
files = run('ls -ltr /home/ndsuser/enc/data/dbSchema_1/catalogue_24802')
run('rm -rf /usr/rosh/ENC_Analysis/*')
run('cp /home/ndsuser/enc/data/dbSchema_1/catalogue_24802/* /usr/rosh/ENC_Analysis/')
count = run('ls -l /usr/rosh/ENC_Analysis/ | wc -l')
os.chdir('/usr/rosh/ENC_Analysis/')
for file in os.listdir('/usr/rosh/ENC_Analysis/'):
print file
If i run this code, i gets the issue as below.
File "C:/Work/Scripts/VOD/ENC.py", line 20, in get_Connection
os.chdir('/usr/rosh/ENC_Analysis/')
WindowsError: [Error 3] The system cannot find the path specified: '/usr/rosh/ENC_Analysis/'
I know this issue is due to the fact that system is not able to find a path in the Windows machine. How can i get to the path in a Linux Server from a Windows machine?
Upvotes: 1
Views: 449
Reputation: 2818
You can set PyCharm up to automatically copy the python script to a remote server and run it there. The PyCharm documentation for this is at https://www.jetbrains.com/pycharm/help/configuring-remote-interpreters-via-ssh.html
Since you've already imported paramiko, you could also send all the relevant commands over an ssh session to the linux server, while running the script locally. This seems a bit more awkward, but would still work.
sshconnection = paramiko.SSHClient()
sshconnection.connect(hostname, username=..., password=... )
stdin, stdout, stderr = sshconnection.exec_command('ls -ltr /home/...')
and so on.
Upvotes: 2