Specify FTP port?

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')
	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"
			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))

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?

I tried ftp = FTP('10.redacted':555) etc already


Thanks, still no joy;

ftp = FTP()
ftp.connect('10.redacted', 555)
Traceback (most recent call last):
  File "<buffer>", line 9, in <module>
  File "C:\Users\patrick.gillian\.ignition\cache\gw10.redacted_8088_8043_main\C0\pylib\ftplib.py", line 129, in connect
    raise socket.error, msg
socket.error: (10061, 'Connection refused')

Running this in script console (being naughty and running the designer on the gateway VM...runs and hides from Phil's big stick)

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...

1 Like

Does the IP address really start with 10.? This would be a private IP... how are you reaching it from the cloud?


AWS starts on 10.

Site subnets start actually 172.

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...

Still not the same environment as the gateway service.

Heh. Maybe I should change my avatar to the all-seeing eye:


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-> and 10.a.b.c:503->

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.

The cloud firewall was updated and I can now connect, thanks!

'220 Ready'
'230 Logged in'
'250 Requested file action okay, completed'
'226 Transfer Complete'