Getting file matching a pattern from the remote server which matches current date using python
by AshuTrip from LinuxQuestions.org on (#5D43N)
There is a directory in the remote server '/root/' and it contains multiple files. I want to get a file of today's date whose format is 'SleepingCell_*' in my local directory. If this file is not present on today's date then return nothing. Please note: today's date is the date on the remote server (different from local server)
Example:
remote_path = '/root/'
host = '10.4.5.6'
user = 'AshuT'
password = 'AshuTest123'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=user, password=password)
sftp = client.open_sftp()
#sftp_file = []
for i in sftp.listdir(remote_path):
lstatout=str(sftp.lstat(i)).split()[0]
if 'd' not in lstatout:
if fnmatch.fnmatch(i, "SleepingCell_*"):
#code to check if the file's create/update time is today's date


Example:
remote_path = '/root/'
host = '10.4.5.6'
user = 'AshuT'
password = 'AshuTest123'
client = paramiko.SSHClient()
client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
client.connect(host, username=user, password=password)
sftp = client.open_sftp()
#sftp_file = []
for i in sftp.listdir(remote_path):
lstatout=str(sftp.lstat(i)).split()[0]
if 'd' not in lstatout:
if fnmatch.fnmatch(i, "SleepingCell_*"):
#code to check if the file's create/update time is today's date