3
I have a server (Fedora 29) at home running (as root) an ftp done in python with the ports 5000-5003 and 40000-50000 open, the machine is in DMZ
import logging
import sys
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
from pyftpdlib.authorizers import UnixAuthorizer
from pyftpdlib.filesystems import UnixFilesystem
def main():
logger = logging.getLogger()
ch = logging.StreamHandler(sys.stdout)
logger.setLevel(logging.DEBUG)
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
authorizer = UnixAuthorizer(allowed_users=['marcelo'], require_valid_shell=True, global_perm='elradfmwMT')
handler = FTPHandler
handler.authorizer = authorizer
handler.abstracted_fs = UnixFilesystem
handler.passive_ports = (40000, 50000)
handler.log_prefix = '%(username)s@%(remote_ip)s'
server = FTPServer(('',5001), handler)
server.serve_forever()
if __name__ == '__main__':
main()
At work I am like a machine (Fedora 29) with the doors 5000-5003/tcp and 40000-50000/tcp open and in DMZ running a client ftplib.
from ftplib import FTP
ftp = FTP('')
ftp.connect('*****',5001)
ftp.login(user='****',passwd='*****')
ftp.set_debuglevel(2)
ftp.set_pasv(False)
#ftp.cwd('/home/marcelo')
response = ftp.retrlines('LIST')
print("response: %s",response)
def uploadFile():
filename = 'arquivo5.txt'
ftp.storbinary('STOR '+filename, open(filename,'rb'))
def downloadFile():
filename = 'backup.dmp'
localfile = open(filename, 'wb')
ftp.retrbinary('RETR '+filename, localfile.write, 2048)
localfile.close()
#uploadFile()
#downloadFile()
ftp.quit()
In the client I receive the following reply: ftplib.error_perm: 501 Rejected data Connection to Foreign address 192.168.0.9:47123.
And on the server: pyftpdlib - WARNING - Imprint@... -> 501 Rejected data Connection to Foreign address 192.168.0.9:47123.
Note: astericas are my public ip Obs2: In the browser works perfectly
I believe the problem is the type C address I’m sending to the server but I don’t know how to fix it.
thank you.
You tested the connection by running the client and server on the same machine?
– jsbueno