from ftplib import FTP # 连接到FTP服务器 ftp = FTP('10.129.250.27') ftp.login(user='用户名', passwd='密码') # 列出FTP服务器上的文件和目录 ftp.retrlines('LIST') # 下载文件 filename = 'robots.txt' with open(filename, 'wb') as file: ftp.retrbinary('RETR ' + filename, file.write) # 上传文件 filename = 'robots.txt' with open(filename, 'rb') as file: ftp.storbinary('STOR ' + filename, file) # 断开FTP连接 ftp.quit()