-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.py
35 lines (23 loc) · 803 Bytes
/
a.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import ftplib
import os
import pyperclip
HOSTNAME = "hostname"
USERNAME = "uname"
PASSWORD = "pass"
UPLOAD_DIRECTORY = "/httpdocs/baikral/"
ftp_server = ftplib.FTP(HOSTNAME, USERNAME, PASSWORD)
ftp_server.encoding = "utf-8"
directory = "/home/bai/Pictures/"
ftp_server.cwd(UPLOAD_DIRECTORY)
file_list = [f for f in os.listdir(directory) if f.endswith('.png')]
latest_file = max(file_list, key=lambda f: os.path.getmtime(os.path.join(directory, f)))
if latest_file in ftp_server.nlst():
print(f"{latest_file} skipping.")
else:
with open(os.path.join(directory, latest_file), "rb") as file:
ftp_server.storbinary(f"STOR {latest_file}", file)
print(f"{latest_file} uploaded.")
ftp_server.dir()
copy= "urlofhosttocopy/"+latest_file
pyperclip.copy(copy)
ftp_server.quit()