writing windows file and directory path to linux remote server in Python?
up vote
-1
down vote
favorite
def srv_connect(USERNAME=parser.get('init', 'USERNAME'),
PASSWORD=parser.get('init', 'PASSWORD'),
HOST=parser.get('init', 'HOST')):
global s #making s a global variable to return
try:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
s = pysftp.Connection(HOST, username=USERNAME, password=PASSWORD, cnopts=cnopts)
except Exception, e:
print("Failed to connect to " + HOST)
print (str(e))
finally:
return (s)
def dir_search(s):
try:
for i in parser['data']:
print i
data = parser.get('data', i).split()
#get contents of each dir at data[1]
for (path, dirs, files) in os.walk(data[1]): #gets all the dir paths
#print path, files
#I think I will need another for loop in order to get the user GID, UID and UNAME
for file in files:
file_out = os.path.join(path,file) #joins dir paths and file paths
print file_out
for file_put in file_out:
#write to remote host
s.put_r(file_out, file_out, preserve_mtime=True)
print (file_put)
print file_out
print data
except Exception, e:
print (str(e))
I am using configparser
to create a configuration file. The config file has an unlimited amount of potential read paths from the local host. The local host needs to send and write the data to a RHEL6.10 box. The path structure from the local host needs to be mirrored on the remote host. Then the ownership of the file needs to be changed with pysftp.chown()
.
So I think I have the read structure down. The problem I am encountering is writing to the server given the directory path. It recursively looks the the given folder for any files and files in subdirectories. Then it has to write them. I plan on using pysftp.put_r
to recursively write to the remote server.
Under def dir_search
I am having trouble within my for
structure.
Here is an example config:
[data]
ID0 = 1 C:UsersAdministratorDocuments /tmp 465 5000
python sftp pysftp
add a comment |
up vote
-1
down vote
favorite
def srv_connect(USERNAME=parser.get('init', 'USERNAME'),
PASSWORD=parser.get('init', 'PASSWORD'),
HOST=parser.get('init', 'HOST')):
global s #making s a global variable to return
try:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
s = pysftp.Connection(HOST, username=USERNAME, password=PASSWORD, cnopts=cnopts)
except Exception, e:
print("Failed to connect to " + HOST)
print (str(e))
finally:
return (s)
def dir_search(s):
try:
for i in parser['data']:
print i
data = parser.get('data', i).split()
#get contents of each dir at data[1]
for (path, dirs, files) in os.walk(data[1]): #gets all the dir paths
#print path, files
#I think I will need another for loop in order to get the user GID, UID and UNAME
for file in files:
file_out = os.path.join(path,file) #joins dir paths and file paths
print file_out
for file_put in file_out:
#write to remote host
s.put_r(file_out, file_out, preserve_mtime=True)
print (file_put)
print file_out
print data
except Exception, e:
print (str(e))
I am using configparser
to create a configuration file. The config file has an unlimited amount of potential read paths from the local host. The local host needs to send and write the data to a RHEL6.10 box. The path structure from the local host needs to be mirrored on the remote host. Then the ownership of the file needs to be changed with pysftp.chown()
.
So I think I have the read structure down. The problem I am encountering is writing to the server given the directory path. It recursively looks the the given folder for any files and files in subdirectories. Then it has to write them. I plan on using pysftp.put_r
to recursively write to the remote server.
Under def dir_search
I am having trouble within my for
structure.
Here is an example config:
[data]
ID0 = 1 C:UsersAdministratorDocuments /tmp 465 5000
python sftp pysftp
put_r
already uploads whole directory structure. Simply call it once for every path inparser['data']
. No need for anywalk
and nestedfor
loops.
– Martin Prikryl
Nov 10 at 7:49
Do you mind showing me? I am relatively new to Python. This is probably my fourth time using it.
– Chris Zog
Nov 12 at 19:15
So, one of my build requirements is to first get the files and their paths, then wait X seconds. This is defined in the config.ini file. I'm not sure what my boss's reasoning for it is, he is a programmer not me. One thing I ran into while trying to call pysftp.put_r() isAttributeError: 'module' object has no attribute 'put_r'
– Chris Zog
Nov 12 at 19:19
You have too many questions for a single post. With is Q&A site, not a support forum. So maybe you should start with a separate question on callingput_r
with Minimal, Complete, and Verifiable example.
– Martin Prikryl
Nov 13 at 7:26
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
def srv_connect(USERNAME=parser.get('init', 'USERNAME'),
PASSWORD=parser.get('init', 'PASSWORD'),
HOST=parser.get('init', 'HOST')):
global s #making s a global variable to return
try:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
s = pysftp.Connection(HOST, username=USERNAME, password=PASSWORD, cnopts=cnopts)
except Exception, e:
print("Failed to connect to " + HOST)
print (str(e))
finally:
return (s)
def dir_search(s):
try:
for i in parser['data']:
print i
data = parser.get('data', i).split()
#get contents of each dir at data[1]
for (path, dirs, files) in os.walk(data[1]): #gets all the dir paths
#print path, files
#I think I will need another for loop in order to get the user GID, UID and UNAME
for file in files:
file_out = os.path.join(path,file) #joins dir paths and file paths
print file_out
for file_put in file_out:
#write to remote host
s.put_r(file_out, file_out, preserve_mtime=True)
print (file_put)
print file_out
print data
except Exception, e:
print (str(e))
I am using configparser
to create a configuration file. The config file has an unlimited amount of potential read paths from the local host. The local host needs to send and write the data to a RHEL6.10 box. The path structure from the local host needs to be mirrored on the remote host. Then the ownership of the file needs to be changed with pysftp.chown()
.
So I think I have the read structure down. The problem I am encountering is writing to the server given the directory path. It recursively looks the the given folder for any files and files in subdirectories. Then it has to write them. I plan on using pysftp.put_r
to recursively write to the remote server.
Under def dir_search
I am having trouble within my for
structure.
Here is an example config:
[data]
ID0 = 1 C:UsersAdministratorDocuments /tmp 465 5000
python sftp pysftp
def srv_connect(USERNAME=parser.get('init', 'USERNAME'),
PASSWORD=parser.get('init', 'PASSWORD'),
HOST=parser.get('init', 'HOST')):
global s #making s a global variable to return
try:
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None
s = pysftp.Connection(HOST, username=USERNAME, password=PASSWORD, cnopts=cnopts)
except Exception, e:
print("Failed to connect to " + HOST)
print (str(e))
finally:
return (s)
def dir_search(s):
try:
for i in parser['data']:
print i
data = parser.get('data', i).split()
#get contents of each dir at data[1]
for (path, dirs, files) in os.walk(data[1]): #gets all the dir paths
#print path, files
#I think I will need another for loop in order to get the user GID, UID and UNAME
for file in files:
file_out = os.path.join(path,file) #joins dir paths and file paths
print file_out
for file_put in file_out:
#write to remote host
s.put_r(file_out, file_out, preserve_mtime=True)
print (file_put)
print file_out
print data
except Exception, e:
print (str(e))
I am using configparser
to create a configuration file. The config file has an unlimited amount of potential read paths from the local host. The local host needs to send and write the data to a RHEL6.10 box. The path structure from the local host needs to be mirrored on the remote host. Then the ownership of the file needs to be changed with pysftp.chown()
.
So I think I have the read structure down. The problem I am encountering is writing to the server given the directory path. It recursively looks the the given folder for any files and files in subdirectories. Then it has to write them. I plan on using pysftp.put_r
to recursively write to the remote server.
Under def dir_search
I am having trouble within my for
structure.
Here is an example config:
[data]
ID0 = 1 C:UsersAdministratorDocuments /tmp 465 5000
python sftp pysftp
python sftp pysftp
asked Nov 9 at 18:13
Chris Zog
13
13
put_r
already uploads whole directory structure. Simply call it once for every path inparser['data']
. No need for anywalk
and nestedfor
loops.
– Martin Prikryl
Nov 10 at 7:49
Do you mind showing me? I am relatively new to Python. This is probably my fourth time using it.
– Chris Zog
Nov 12 at 19:15
So, one of my build requirements is to first get the files and their paths, then wait X seconds. This is defined in the config.ini file. I'm not sure what my boss's reasoning for it is, he is a programmer not me. One thing I ran into while trying to call pysftp.put_r() isAttributeError: 'module' object has no attribute 'put_r'
– Chris Zog
Nov 12 at 19:19
You have too many questions for a single post. With is Q&A site, not a support forum. So maybe you should start with a separate question on callingput_r
with Minimal, Complete, and Verifiable example.
– Martin Prikryl
Nov 13 at 7:26
add a comment |
put_r
already uploads whole directory structure. Simply call it once for every path inparser['data']
. No need for anywalk
and nestedfor
loops.
– Martin Prikryl
Nov 10 at 7:49
Do you mind showing me? I am relatively new to Python. This is probably my fourth time using it.
– Chris Zog
Nov 12 at 19:15
So, one of my build requirements is to first get the files and their paths, then wait X seconds. This is defined in the config.ini file. I'm not sure what my boss's reasoning for it is, he is a programmer not me. One thing I ran into while trying to call pysftp.put_r() isAttributeError: 'module' object has no attribute 'put_r'
– Chris Zog
Nov 12 at 19:19
You have too many questions for a single post. With is Q&A site, not a support forum. So maybe you should start with a separate question on callingput_r
with Minimal, Complete, and Verifiable example.
– Martin Prikryl
Nov 13 at 7:26
put_r
already uploads whole directory structure. Simply call it once for every path in parser['data']
. No need for any walk
and nested for
loops.– Martin Prikryl
Nov 10 at 7:49
put_r
already uploads whole directory structure. Simply call it once for every path in parser['data']
. No need for any walk
and nested for
loops.– Martin Prikryl
Nov 10 at 7:49
Do you mind showing me? I am relatively new to Python. This is probably my fourth time using it.
– Chris Zog
Nov 12 at 19:15
Do you mind showing me? I am relatively new to Python. This is probably my fourth time using it.
– Chris Zog
Nov 12 at 19:15
So, one of my build requirements is to first get the files and their paths, then wait X seconds. This is defined in the config.ini file. I'm not sure what my boss's reasoning for it is, he is a programmer not me. One thing I ran into while trying to call pysftp.put_r() is
AttributeError: 'module' object has no attribute 'put_r'
– Chris Zog
Nov 12 at 19:19
So, one of my build requirements is to first get the files and their paths, then wait X seconds. This is defined in the config.ini file. I'm not sure what my boss's reasoning for it is, he is a programmer not me. One thing I ran into while trying to call pysftp.put_r() is
AttributeError: 'module' object has no attribute 'put_r'
– Chris Zog
Nov 12 at 19:19
You have too many questions for a single post. With is Q&A site, not a support forum. So maybe you should start with a separate question on calling
put_r
with Minimal, Complete, and Verifiable example.– Martin Prikryl
Nov 13 at 7:26
You have too many questions for a single post. With is Q&A site, not a support forum. So maybe you should start with a separate question on calling
put_r
with Minimal, Complete, and Verifiable example.– Martin Prikryl
Nov 13 at 7:26
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53231252%2fwriting-windows-file-and-directory-path-to-linux-remote-server-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
put_r
already uploads whole directory structure. Simply call it once for every path inparser['data']
. No need for anywalk
and nestedfor
loops.– Martin Prikryl
Nov 10 at 7:49
Do you mind showing me? I am relatively new to Python. This is probably my fourth time using it.
– Chris Zog
Nov 12 at 19:15
So, one of my build requirements is to first get the files and their paths, then wait X seconds. This is defined in the config.ini file. I'm not sure what my boss's reasoning for it is, he is a programmer not me. One thing I ran into while trying to call pysftp.put_r() is
AttributeError: 'module' object has no attribute 'put_r'
– Chris Zog
Nov 12 at 19:19
You have too many questions for a single post. With is Q&A site, not a support forum. So maybe you should start with a separate question on calling
put_r
with Minimal, Complete, and Verifiable example.– Martin Prikryl
Nov 13 at 7:26