python - FTP server Client using ftplib -
i trying implement both ftp server , client transfer files, unable make connection between 2 using ftplib module in python....
this did, how can fix code? there approach?
code server : -
#making important imports file transfer : 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 client. print 'got connection from', addr c.send('thank connecting') ftp_object_server.close() # close connection code client : -
ftplib import ftp ftp_object_client=ftp() host = "121.0.0.1" # local machine name port = 1227 # reserve port service. #---------creating own set of username , passwords ------------------------# username=['abc','efg','hij'] password=['123'] input_user_name=raw_input('enter username') input_user_password=raw_input('enter password') if input_user_name in username , input_user_password in password: ftp_object_client.connect(host) print ftp_object_client.recv(1024) ftp_object_client.close()
the ftplib module standard library covers client part of ftp protocol. did trying open 2 connections 121.0.0.1. i'm assuming meant localhost, 127.0.0.1 anyway.
not knowing trying achieve, there options:
- transfer files using http, use
python -m simplehttpserver(orpython3 -m http.serverin python3) , requests client - use prexisting solution (see answers one line ftp server in python)
- implement own server
Comments
Post a Comment