Search code examples
pythonpython-2.7ftpftplib

How to connect remote Python FTP server to local Python FTP client


I am using python FTP server and client program. My need is to run Python FTP server on a remote machine that is connected on the same network as my local machine. FTP client will run from local machine, I need to connect FTP server with my FTP client running on local machine.

Please help!

This is my ftpserver.py:

from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler

authorizer = DummyAuthorizer()
authorizer.add_user("lokesh", "123", "current_dir", perm="elradfmw")
authorizer.add_anonymous("curent_dir", perm="elradfmw")

handler = FTPHandler
handler.authorizer = authorizer

server=FTPServer(("localhost",8080),handler)
server.serve_forever()

This is my ftpclient.py that needs to connect with the above server:

from ftplib import FTP

ftp = FTP('')
host='localhost'
port=8080
ftp.connect(host,port)
ftp.login()

print(ftp.getwelcome())
print('Current Directory ',ftp.pwd())

ftp.dir()

ftp.quit()

When I test my server and client on same machine it worked. But when I run the same server on another machine and tried to connect with my client it gave me error:

error: [Errno 10061] No connection could be made because the target machine actively refused it


Solution

  • If you run the client on another machine, you have to connect to the host of the server, not to "localhost":

    host='<server_host>'
    

    Run ipconfig on your Windows server machine and look for "IPv4 address".