-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
62 lines (48 loc) · 1.63 KB
/
client.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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (c) 2023. All rights reserved by Woliul Hasan. Fork me on https://github.com/hmwoliul
"""
* Created in PyCharm.
* Project Name: ftptest
* User: woliul
* Date: 6/19/23
* Time: 11:48 AM
"""
import ftplib
def ftp_client():
# Connect to the FTP server
ftp = ftplib.FTP("127.0.0.1")
ftp.login(user="admin", passwd="password")
print("Connected to FTP server.")
while True:
print("\n--- Menu ---")
print("1. List files")
print("2. Download file")
print("3. Upload file")
print("4. Quit")
choice = input("Enter your choice: ")
if choice == "1":
# List files and directories
files = ftp.nlst()
print("Files and directories on the server:")
for file in files:
print(file)
elif choice == "2":
# Download file
filename = input("Enter the filename to download: ")
with open(filename, "wb") as file:
ftp.retrbinary("RETR " + filename, file.write)
print(f"File '{filename}' downloaded successfully.")
elif choice == "3":
# Upload file
filename = input("Enter the filename to upload: ")
with open(filename, "rb") as file:
ftp.storbinary("STOR " + filename, file)
print(f"File '{filename}' uploaded successfully.")
elif choice == "4":
# Quit
ftp.quit()
print("FTP client terminated.")
break
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
ftp_client()