使用ftplib的FTP服务器客户端

2024-04-20 13:59:33 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图实现FTP服务器和客户机来传输文件,但基本上无法使用python中的ftplib模块在这两者之间建立连接。。。。在

这就是我所做的,我如何修复代码? 还有别的办法吗?在

我的服务器的代码:-

       #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

我的客户代码:

^{pr2}$

Tags: the代码from服务器hostforobjectserver
1条回答
网友
1楼 · 发布于 2024-04-20 13:59:33

来自标准库的ftplib模块仅覆盖FTP协议的客户端部分。 所以您所做的就是尝试打开到121.0.0.1的两个连接。我假设你指的是localhost,反正就是127.0.0.1。在

不知道自己到底想实现什么,有一些选择:

  • 使用HTTP传输文件,使用python -m SimpleHTTPServer(或python3中的python3 -m http.server)和{a2}作为客户端
  • 使用已有的解决方案(参见One line ftp server in python的答案)
  • 实现自己的服务器

相关问题 更多 >