大家好日子,
我想知道是否可以看到哪个用户在SFTP服务器上上传了文件?
我必须下载一些文件,并且我想检查已经上传文件的用户(FTP登录或Windows用户)。
提前致谢。
我的部分内容
try:
file.write('Start done.' + '\n')
file.write('Host : ' + str(host) + ':' + str(port) + '\n')
file.write('UserName : ' + str(username) + '\n')
transport = paramiko.Transport((host, port))
transport.connect(username = username, password = password)
sftp = paramiko.SFTPClient.from_transport(transport)
file.write('Connexion done.' + '\n')
for i in sftp.listdir():
lstatout=str(sftp.lstat(i)).split()[0]
if 'd' not in lstatout and i.startswith(templatefilename):
file.write('SourceFolder : ' + path + '\n')
file.write('DestinationFolder : ' + localpath + '\n')
file.write('FileToCopy : ' + i + '\n')
sftp.get(path + i, localpath + i)
#here i would like to create txt file with some informations about my file.
#Most important info is username who has uploaded the file
fname = localpath + i
excel = win32.gencache.EnsureDispatch('Excel.Application')
excel.DisplayAlerts = False
wb = excel.Workbooks.Open(fname)
wb.SaveAs(localpath + filename_destination, FileFormat = 51) #FileFormat = 51 is for .xlsx extension
wb.Close() #FileFormat = 56 is for .xls extension
excel.Application.Quit()
os.remove(localpath + i)
sftp.close()
transport.close()
file.write('------------------------- Download done -------------------------' + '\n')
file.close()
except Exception as e:
print('error : ' + str(e))
file.write('error : ' + str(e) + '\n')
file.close()