Article 5D43N Getting file matching a pattern from the remote server which matches current date using python

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 datelatest?d=yIl2AUoC8zA latest?i=qzhffkO3mIk:N9Y4YU0zLrY:F7zBnMy latest?i=qzhffkO3mIk:N9Y4YU0zLrY:V_sGLiP latest?d=qj6IDK7rITs latest?i=qzhffkO3mIk:N9Y4YU0zLrY:gIN9vFwqzhffkO3mIk
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments