简体   繁体   English

如何将远程 Python FTP 服务器连接到本地 Python FTP 客户端

[英]How to connect remote Python FTP server to local Python FTP client

I am using python FTP server and client program.我正在使用 python FTP 服务器和客户端程序。 My need is to run Python FTP server on a remote machine that is connected on the same network as my local machine.我的需要是在与我的本地机器连接在同一网络上的远程机器上运行Python FTP 服务器 FTP client will run from local machine , I need to connect FTP server with my FTP client running on local machine. FTP 客户端将从本地机器运行,我需要将 FTP 服务器与我在本地机器上运行的 FTP 客户端连接。

Please help!请帮忙!

This is my ftpserver.py :这是我的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:这是我的ftpclient.py ,需要连接上面的服务器:

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错误:[Errno 10061] 无法建立连接,因为目标机器主动拒绝它

If you run the client on another machine, you have to connect to the host of the server, not to "localhost":如果你在另一台机器上运行客户端,你必须连接到服务器的主机,而不是“localhost”:

host='<server_host>'

Run ipconfig on your Windows server machine and look for "IPv4 address".在您的 Windows 服务器机器上运行ipconfig并查找“IPv4 地址”。

将 ftpclient 文件中的port = 1027替换为port = 8080

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM