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.
import os
import system
from ftplib import FTP
import os.path
localpath = "\\\\C:\\Temp\\redacted\\FTP\\"
ftp = FTP('10.redacted')
ftp.login('redacted','redacted')
ftp.cwd('/data/redacted/')
files = []
command = 'LIST'
ftp.retrlines(command, files.append)
for i in range(len(files)):
files[i] = files[i].replace(files[i][0:48], '')
print files
for file in files:
if os.path.exists(localpath + file):
#do nothing
print "exists"
else:
filename = system.file.getTempFile(file)
s=ftp.retrbinary('RETR' + file, open(filename,'wb').write)
print s
system.file.writeFile(localpath + file, system.file.readFileAsBytes(filename))
ftp.close()
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...
Well I'm just gonna have to assume you have all that set up correctly.
Your original post mentions "port forwarding on remote routers", which I don't really understand the necessity of if you're using a VPN setup. But I can only assume you know all the details here...
Well, I have 116 ModbusTCP connections configured this way and they all work and have done for over a year.
Gateway is on 10.a.b.c
OpenVPN tunnel is 172.a.b.c
Each site has a remote router on 4G, with a VPN client cert which gives each site a unique tunnel address of 172.a.b.unique
I setup the device connection in the gateway as 172.a.b.unique:502 and :503 if two devices
Then in the router I port forward from remote address 10.a.b.c (gateway) to local site device, which can be any IP, e.g. 10.a.b.c:502->10.11.12.1:502 and 10.a.b.c:503->10.11.12.2:502
Just need to get the FTP port forward working, I've asked the clouid dev ops eng to have a look at the firewall rules there.
For the sake of testing one script I can't be bothered with message handlers, but putting the above script in a gateway timer script also results in connection refused.
Is there anything in this section of code that would differ between Jython 2.5 and 2.7? This code used to run on 7.9.13, now we are on 8.1.35, and the section that checks if the file already exists doesn't work anymore - if there is a trigger all files are uploaded instead of just the new ones.