I am trying to upload/download file to local FTP server, but it gives me the error mentioned in title.
For server I am using pyftpdlib
:
import os
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
# instantiate a dummy authorizer
authorizer = DummyAuthorizer()
# instantiate anonymous user to current directory
authorizer.add_anonymous(os.getcwd())
# FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# setup server on localhost, port = 21
address = ('', 21)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 10
server.max_cons_per_ip = 3
# start ftp server
server.serve_forever()
Here is client code:
from ftplib import FTP
# connect to FTP server
client = FTP(host="127.0.0.1")
client.login()
# list the contents of directory
client.retrlines('LIST')
But the FTP
constructor throws:
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it.
Initially I thought it was port issue (I did not specify port from client when connected), so changed server port to 21, which I believe is default port.
When running server code, I get firewall alert, but when I give it the permission it runs normally. How can I connect to server from the client side?