我用Pyftpdlib创建了一个FTP服务器,我希望能够从另一个国家/ IP连接到服务器,我试图将我的脚本(以exe格式)上传到该国其他地区的朋友和我无法连接(简单超时/无效错误)。如何连接到不在我附近的ftp服务器?
服务器
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import requests
import mysql.connector
sqlpass = "THIS ISNT THE PASSWORD"
def ftp_main():
mydb = mysql.connector.connect(
host="remotemysql.com",
port="3306",
user="NOT TELLING",
passwd=sqlpass,
database="NO THANKS"
)
mycursor = mydb.cursor()
mycursor.execute("SELECT Username, Password FROM NO-THANKS")
myresult = mycursor.fetchall()
Username, Password = myresult[0]
print(Username + " " + Password)
authorizer = DummyAuthorizer()
authorizer.add_user(Username, Password, 'C:/', perm='elradfmwMT')
authorizer.add_anonymous('C:/')
handler = FTPHandler
handler.authorizer = authorizer
handler.banner = "Test Banner"
# Instantiate FTP server class and listen on 0.0.0.0:2121
address = ('0.0.0.0', 21)
server = FTPServer(address, handler)
# start ftp server
server.serve_forever()
ftp_main()
客户
from ftplib import FTP
ftp = FTP('104.193.20.211')
ftp.login("user", "pass")
ftp.retrlines('LIST')
ftp.cwd("Users/TEST/Desktop")
ftp.retrlines('LIST')
getfile = 'test1.txt'
command = 'RETR'
ftp.retrbinary(command + " " + getfile, open('test1.txt', 'wb').write)
我希望连接并能够列出文件,但我无法连接。
(根据你的说法我假设它只在你连接到远程网络时不起作用。)
因为你有连接问题,似乎问题是由网络引起的。从编程的角度来看,无论您是否连接到本地网络上的IP都无关紧要。
检查这些可能的问题: