-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload.py
More file actions
41 lines (31 loc) · 1.36 KB
/
upload.py
File metadata and controls
41 lines (31 loc) · 1.36 KB
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
36
37
38
39
40
41
from ftplib import FTP
import os
def upload_file_to_ftp(ftp_server, username, password, local_file_path):
try:
# Connect to the FTP server
ftp = FTP(ftp_server)
ftp.login(username, password)
# Read the remote folder from the text file
with open("uploaded_files.txt", 'r') as folder_file:
remote_folder = folder_file.read().strip()
# Change to the remote folder (create it if it doesn't exist)
ftp.cwd(remote_folder)
# Open the local file in binary mode
with open(local_file_path, 'rb') as local_file:
# Upload the file to the server
ftp.storbinary('STOR ' + os.path.basename(local_file_path), local_file)
print(f"File '{os.path.basename(local_file_path)}' uploaded successfully to '{remote_folder}' on {ftp_server}")
# Clear the contents of the text file after successful upload
with open("uploaded_files.txt", 'w') as folder_file:
folder_file.write("")
except Exception as e:
print(f"Error: {e}")
finally:
# Close the FTP connection
ftp.quit()
# Replace these values with your FTP server details and file paths
ftp_server = 'ftp.adisingh.in'
username = 'tgftpbot@adisingh.in'
password = 'eB]++DGxPGEW'
local_file_path = 'index.php'
upload_file_to_ftp(ftp_server, username, password, local_file_path)