Python FTP

I have a need to upload a text file to a printer at the touch of a button…

This is the script behind the button…

import os import system import ftplib filename = "\\\BRPAAPP001\zebra\\bufferclearlable.txt" print filename if system.tag.read("PRT_Select/PrinterSelected").value == 1: ftp = ftplib.FTP("10.155.3.111") else: ftp = ftplib.FTP("10.155.3.112") ftp.login("ignition") myfile = open(filename, 'r') ftp.storlines('STOR ' + filename, myfile) myfile.close() ftp.quit()

I cannot seem to get the filename set correcty with the slashes. Can someone help me?

Are you looking for a double backslash at the beginning?

filename = "\\\\BRPAAPP001\\zebra\\bufferclearlable.txt"

Out of curiosity, is this going to a print server?

No dice…

Traceback (most recent call last):
File “event:actionPerformed”, line 10, in
IOError: (2, ‘No such file or directory’, ‘\\BRPAAPP001\zebra\bufferclearlable.txt’)

Its s Zebra Printer, so they are a bunch of ZPL commands to clear the buffer and then print a label indicating that the buffer is clear…

Try adding an r

filename = r"\\BRPAAPP001\zebra\bufferclearlable.txt"

I seem to remember reading about using PUT instead of STOR. Just can’t quite remember.

Also, you can try using an FTP client like FileZilla to test transfers before scripting.

Thanks Jordan, I have tested manual transfers… I can do the transfer fine from my laptop in python and it works just fine, unfortunately when I move it to Ignition is where I start getting the errors.

Be aware that you are using Jython and not CPython in Ignition. You are trying to open a file from a network path. Java and windows network paths doesn’t work in a easy way.

Before doing the FTP thing, be sure that you can reach that file from network location.

Try to get the content of the file and printing in the console using support.inductiveautomation.com … string.htm

For configuring network path to access in Ignition, see:
support.inductiveautomation.com … _drive.htm

I hope this help. Regards,