Sending file to print server using ftplib

Joshua Burvill josh at mri.com.au
Wed May 19 21:40:20 EDT 2004


Hello,

I am trying to print something to a print server using the following
function
but I get errors, does anyone have any pointers?

Rgds, Josh

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in ?
    mk_zeb_label()
  File "\\mrisydney\ZopeBBAp\Extensions\mk_zeb_label.py", line 38, in
mk_zeb_label
    val=ftp.storlines("STOR " + portname, file_handle)
  File "C:\Python21\lib\ftplib.py", line 382, in storlines
    conn = self.transfercmd(cmd)
  File "C:\Python21\lib\ftplib.py", line 296, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Python21\lib\ftplib.py", line 273, in ntransfercmd
    host, port = parse227(self.sendcmd('PASV'))
  File "C:\Python21\lib\ftplib.py", line 229, in sendcmd
    return self.getresp()
  File "C:\Python21\lib\ftplib.py", line 202, in getresp
    raise error_perm, resp
error_perm: 501 command not supported.

########################
## SCRIPT STARTS HERE ##
########################

def mk_zeb_label():

    from ftplib import FTP
    import string, cStringIO




    ## Create file-handle to a "file-like" string
    file_handle=cStringIO.StringIO()

    printserver_ip="192.168.2.15"
    portname="COM1"
    zpt_code="""
^XA
^cfd,36,20
^by3,,50
^fo470,50
^abn,48,30^fdREPAIR^fs
^fo50,150
^fdSome text goes here.^fs
^fdSome text goes here.^fs
^fdSome text goes here.^fs
^fo50,50
^bc^fd114567^fs
^XZ
"""


    file_handle.write(zpt_code)
    ftp=FTP(printserver_ip)
    ftp.login("","")

    val=ftp.storlines("STOR " + portname, file_handle)

    return val





More information about the Python-list mailing list