我正在尝试同时实现 FTP 服务器和客户端来传输文件,但我基本上无法使用ftplib
python 中的模块在两者之间建立连接....
这就是我所做的,我该如何修复代码?还有另一种方法吗?
我的服务器的代码:-
#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()