[英]FTP server Client using ftplib
我試圖同時實現一個FTP服務器和一個客戶端來傳輸文件,但是我基本上無法使用python中的ftplib
模塊在兩者之間建立連接。
這就是我所做的,如何修復代碼? 還有其他方法嗎?
我服務器的代碼:-
#making the important imports for file transfer :
from ftplib import FTP
ftp_object_server=FTP()
#s = socket.socket()
host = "121.0.0.1"
port = 1227
ftp_object_server.connect(host,port)
while True:
c, addr = ftp_object_server.accept()
print c
print addr# Establish connection with client.
print 'Got connection from', addr
c.send('Thank you for connecting')
ftp_object_server.close() # Close the connection
客戶代碼:-
from ftplib import FTP
ftp_object_client=FTP()
host = "121.0.0.1" # Get local machine name
port = 1227 # Reserve a port for your service.
#---------Creating My Own Set of username and passwords ------------------------#
Username=['abc','efg','hij']
Password=['123']
input_user_name=raw_input('Enter the Username')
input_user_password=raw_input('Enter the password')
if input_user_name in Username and input_user_password in Password:
ftp_object_client.connect(host)
print ftp_object_client.recv(1024)
ftp_object_client.close()
標准庫中的ftplib模塊僅涵蓋FTP協議的客戶端部分。 所以,您要做的是嘗試打開兩個與121.0.0.1
連接。 我假設您的意思是localhost
,無論如何它是127.0.0.1
。
有一些選擇不知道您實際要實現的目標:
python -m SimpleHTTPServer
(或python3 -m http.server
)並將請求作為客戶端
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.