Can someone tell me why my variable will only return all .txt files or all .log files but not both together. I thought I understood this, as I have used similar cases before with an if statement and qn endswith method of text or log extension. But, with getting files from a server it’s only allowing me to get one or another. I’m sure it’s the syntax … I have very little experience with Python. Any help is appreciated:
This line works fine or a variation with .txt:
apattern = '"*.log"'
However, this line searches for .log files only:
apattern = (('"*.txt" ') or ('"*.log" '))
Code:
import paramiko
import sys
import os
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('10.5.48.72', username='root', password='*****')
apath = '/'
apattern = '"*.{txt,log}"' #(('"*.txt" ') and ('"*.log" '))
rawcommand = 'find {path} -name {pattern}'
command = rawcommand.format(path=apath, pattern=apattern)
stdin, stdout, stderr = ssh.exec_command(command)
filelist = stdout.read().splitlines()
ftp = ssh.open_sftp()
for afile in filelist:
(head, filename) = os.path.split(afile)
print(filename)
ftp.get(afile, 'c:\\ANewOne\\' + filename) #'./'+filename)
ftp.close()
ssh.close()
Should combine the extensions using unix-style shell expansion.
Another variant for the
findutility would beMaybe you can try this, too. This will construct the command