Script of FTP using SSL

Hi Team,
using ignition vision 8.1.17 and OS windows server 2019. Please let me know if more information is required.

Client want us to use FTP with TLS/SSL encryption.
image

after looking at some sample code for python. Following script is written on gateway. But execution of the script gives error on the wrapper.

		from ftplib import FTP_TLS
		ftps = FTP_TLS('ftptest.server')
		ftps.login('ch\ftpuser', 'pass') # Username, Password
		ftps.prot_p()
		ftp_path = "/" # Notice the forward slashes
		ftps.cwd(ftp_path)
		print str(ftps.pwd())
		ftps.storbinary('STOR ' + filename, file_object)

Error which i am currently getting on wrapper log file is:

INFO   | jvm 1    | 2022/07/18 15:46:00 | E [S.S.ScheduledTask             ] [03:46:00]: Error executing scheduled script: Ignition_Vision/ScheduledScript(name=Report 1, cronExpression=* * * * *, enabled=true). Repeat errors of this type will be logged as 'debug' messages. project=Ignition_Vision
INFO   | jvm 1    | 2022/07/18 15:46:00 | com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
INFO   | jvm 1    | 2022/07/18 15:46:00 |   File "<Report 1>", line 126, in onScheduledEvent
INFO   | jvm 1    | 2022/07/18 15:46:00 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 653, in login
INFO   | jvm 1    | 2022/07/18 15:46:00 |     return FTP.login(self, user, passwd, acct)
INFO   | jvm 1    | 2022/07/18 15:46:00 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 393, in login
INFO   | jvm 1    | 2022/07/18 15:46:00 |     if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
INFO   | jvm 1    | 2022/07/18 15:46:00 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 249, in sendcmd
INFO   | jvm 1    | 2022/07/18 15:46:00 |     return self.getresp()
INFO   | jvm 1    | 2022/07/18 15:46:00 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 224, in getresp
INFO   | jvm 1    | 2022/07/18 15:46:00 |     raise error_perm, resp
INFO   | jvm 1    | 2022/07/18 15:46:00 | ftplib.error_perm: 530 User cannot log in.
INFO   | jvm 1    | 2022/07/18 15:46:00 | 
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyException.doRaise(PyException.java:211)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.Py.makeException(Py.java:1638)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.Py.makeException(Py.java:1642)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.getresp$17(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:225)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:134)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyFunction.__call__(PyFunction.java:416)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyMethod.__call__(PyMethod.java:126)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.sendcmd$20(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:249)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:150)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyFunction.__call__(PyFunction.java:426)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyMethod.__call__(PyMethod.java:141)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.login$28(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:397)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:187)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyFunction.__call__(PyFunction.java:449)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyMethod.__call__(PyMethod.java:185)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.login$47(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:653)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:158)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyFunction.__call__(PyFunction.java:437)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyMethod.__call__(PyMethod.java:156)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.pycode._pyx94.onScheduledEvent$1(<Report 1>:470)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.pycode._pyx94.call_function(<Report 1>)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyFunction.function___call__(PyFunction.java:474)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyFunction.__call__(PyFunction.java:469)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at org.python.core.PyFunction.__call__(PyFunction.java:464)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:831)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:813)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:806)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:994)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:871)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at com.inductiveautomation.ignition.common.script.ScheduledScriptManager$ScheduledScriptTask.run(ScheduledScriptManager.java:173)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at com.inductiveautomation.ignition.common.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java:239)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	at java.base/java.lang.Thread.run(Unknown Source)
INFO   | jvm 1    | 2022/07/18 15:46:00 | Caused by: org.python.core.PyException: ftplib.error_perm: 530 User cannot log in.
INFO   | jvm 1    | 2022/07/18 15:46:00 | 	... 45 common frames omitted

Try ch\\ftpuser as your username, backslash is an escape character and \f is an ascii form feed. Or even if that’s a sanitized username you’re still probably feeding it an escaped ascii character instead of a backslash.

Thanks for quick Response Kevin. I will try it and let you know the outcome.

Hi Kevin,
Sorry there were few things which we were trying to test the FTP connection going out. Today we able to connect using filezza successfully.
Ignition is giving me following error

E [S.S.ScheduledTask             ] [23:07:21]: Error executing scheduled script: Ignition_Vision/ScheduledScript(name=Report 1, cronExpression=* * * * *, enabled=true). Repeat errors of this type will be logged as 'debug' messages. project=Ignition_Vision
INFO   | jvm 1    | 2022/08/10 11:07:21 | com.inductiveautomation.ignition.common.script.JythonExecException: Traceback (most recent call last):
INFO   | jvm 1    | 2022/08/10 11:07:21 |   File "<Report 1>", line 142, in onScheduledEvent
INFO   | jvm 1    | 2022/08/10 11:07:21 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 743, in storbinary
INFO   | jvm 1    | 2022/08/10 11:07:21 |     conn = self.transfercmd(cmd, rest)
INFO   | jvm 1    | 2022/08/10 11:07:21 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 376, in transfercmd
INFO   | jvm 1    | 2022/08/10 11:07:21 |     return self.ntransfercmd(cmd, rest)[0]
INFO   | jvm 1    | 2022/08/10 11:07:21 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 693, in ntransfercmd
INFO   | jvm 1    | 2022/08/10 11:07:21 |     conn, size = FTP.ntransfercmd(self, cmd, rest)
INFO   | jvm 1    | 2022/08/10 11:07:21 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\ftplib.py", line 335, in ntransfercmd
INFO   | jvm 1    | 2022/08/10 11:07:21 |     conn = socket.create_connection((host, port), self.timeout)
INFO   | jvm 1    | 2022/08/10 11:07:21 |   File "C:\Program Files\Inductive Automation\Ignition\user-lib\pylib\_socket.py", line 1576, in create_connection
INFO   | jvm 1    | 2022/08/10 11:07:21 |     raise err
INFO   | jvm 1    | 2022/08/10 11:07:21 | _socket.error: [Errno 10061] Connection refused
INFO   | jvm 1    | 2022/08/10 11:07:21 | 
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyException.doRaise(PyException.java:239)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.Py.makeException(Py.java:1638)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.Py.makeException(Py.java:1642)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.Py.makeException(Py.java:1646)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at _socket$py.create_connection$133(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/_socket.py:1578)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at _socket$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/_socket.py)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:141)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.__call__(PyFunction.java:426)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.ntransfercmd$26(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:372)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:168)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.__call__(PyFunction.java:437)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyMethod.__call__(PyMethod.java:169)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.ntransfercmd$51(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:697)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:168)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.__call__(PyFunction.java:437)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyMethod.__call__(PyMethod.java:156)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.transfercmd$27(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:376)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:168)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.__call__(PyFunction.java:437)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyMethod.__call__(PyMethod.java:156)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.storbinary$54(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py:755)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at ftplib$py.call_function(C:/Program Files/Inductive Automation/Ignition/user-lib/pylib/ftplib.py)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:158)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.__call__(PyFunction.java:437)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyMethod.__call__(PyMethod.java:156)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.pycode._pyx313.onScheduledEvent$1(<Report 1>:454)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.pycode._pyx313.call_function(<Report 1>)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyTableCode.call(PyTableCode.java:173)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyBaseCode.call(PyBaseCode.java:306)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.function___call__(PyFunction.java:474)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.__call__(PyFunction.java:469)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at org.python.core.PyFunction.__call__(PyFunction.java:464)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:831)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at com.inductiveautomation.ignition.common.script.ScriptManager.runFunction(ScriptManager.java:813)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$TrackingProjectScriptManager.runFunction(ProjectScriptLifecycle.java:806)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at com.inductiveautomation.ignition.common.script.ScriptManager$ScriptFunctionImpl.invoke(ScriptManager.java:994)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at com.inductiveautomation.ignition.gateway.project.ProjectScriptLifecycle$AutoRecompilingScriptFunction.invoke(ProjectScriptLifecycle.java:871)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at com.inductiveautomation.ignition.common.script.ScheduledScriptManager$ScheduledScriptTask.run(ScheduledScriptManager.java:173)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at com.inductiveautomation.ignition.common.util.ExecutionQueue$PollAndExecute.run(ExecutionQueue.java:239)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	at java.base/java.lang.Thread.run(Unknown Source)
INFO   | jvm 1    | 2022/08/10 11:07:21 | Caused by: org.python.core.PyException: _socket.error: [Errno 10061] Connection refused
INFO   | jvm 1    | 2022/08/10 11:07:21 | 	... 52 common frames omitted

Check your firewalls? from another FTP client on the same machine? This is a basic networking problem, not a programming issue like before.

Thanks Kevin, That is what we were thinking.

We have installed Filezilla on same machine it is working fine. Attached is the setting of filezilla

image

This Issue is resloved.
It was found that port number was getting changed by the end server. so have to add following code to deal with it.

_old_makepasv = FTP_TLS.makepasv# Get current IP and Port Setting			
		def _new_makepasv(self):
			host,port = _old_makepasv(self)
			print host,port
			host = self.sock.getpeername()[0]
			return host,port
			print host,port
		FTP_TLS.makepasv = _new_makepasv