I have a script to retrieve files via FTP after an event. This was working fine, however we then changed our architecture to move the gateway into the cloud, as a result we had to setup port forwarding on our remote routers.
from ftplib import FTP
localpath = "\\\\C:\\Temp\\redacted\\FTP\\"
ftp = FTP('10.redacted')
files = 
command = 'LIST'
for i in range(len(files)):
files[i] = files[i].replace(files[i][0:48], '')
for file in files:
if os.path.exists(localpath + file):
filename = system.file.getTempFile(file)
s=ftp.retrbinary('RETR' + file, open(filename,'wb').write)
system.file.writeFile(localpath + file, system.file.readFileAsBytes(filename))
I can successfully connect and retrieve the files using FileZilla with a port forward setup on 555:21, 556:20, however this is a manual process and I would like to return it to be automated.
Is it possible to specify the port in the above script?
Well, just a networking error at this point. Connection refused is what it is. You have something configured wrong, or there's a firewall blocking it, or you have the wrong/IP port, or it's not reachable, etc...