0
I have a script that generates a CSV file and saves with the name of the current date. I’m trying to make a script that checks the latest created file and sends it to the FTP server.
How can I do that?
My script below:
import pysftp
import datetime
import os
import glob
myHostname = 'sftp'
myUsername = 'user'
myPassword = 'password'
cnopts = pysftp.CnOpts() cnopts = pysftp.CnOpts(knownhosts=r'C:\Users\Thiago Simas.ssh\known_hosts')
sftp = pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts=cnopts)
list_of_files = glob.glob(r'C:\Users\ThiagoSimas\PycharmProjects\pythonProject*.csv') # para puxar todos os arquivos csv
latest_file = max(list_of_files, key=os.path.getctime) # para pegar o ultimo arquivo na pasta
localFilePath = latest_file
remoteFilePath = '/Teste/
sftp.put(localFilePath, remoteFilePath)
sftp.close()
Missing close quotes in remoteFilePath.
– tomasantunes
Thanks for the help
– Thiago Simas