I know, I need to upgrade, but can't right now on this server.
I'm trying to script ftping, and i suddenly started getting this message:
ImportError: No module named ftplib
This was working, and suddenly stopped working.
It does work from the script console.
I have not tried restarting the gateway.
ftplib exists in C:\Program Files\Inductive Automation\Ignition\user-lib\pylib
import os
from ftplib import FTP
Update: I did restart the gateway service, but not the entire server, and no change.
Update
#2:
I created a tag change script to do the same function, and it ran succesfully once, then I get same message.
Thanks!
Can you share the full script that runs once and then fails subsequently?
It is really simple, just open an ftp connection, grab the files, save them.
I'm getting a similar error with a script that uses the csv library to process the files, where after running once it will be unable to find the csv moduel. I'm about to bounce this to a different server using 8.1. I've tried various versions of the import ftplib, from ftplib import, etc....
if newValue.value:
import os
from ftplib import FTP
import ftplib
logger=system.util.getLogger('CPPVFTP')
time=system.date.now()
#logger.info('Started at '+str(time))
ftp=FTP('xxxxxxxxx')
ftp.login('anonymous','xxxxxxxxx')
ftp.cwd('Data')
#logger.info('FTP Dir done')
ftp.retrlines('LIST')
list=ftp.nlst()
#set local directory
workingdir=system.tag.read('[ADHF]ImportUtility/WorkingDirectory').value
os.chdir(workingdir)
for a in list: #This is run for each file
#ftp and save the file
fp=open(str(a),'wb')
cmd='RETR '+str(a)
ftp.retrbinary(cmd,fp.write)
fp.close()
logger.info('File Saved: '+str(a))
#ftp.disconnect()
ftp.quit()
logger.info('Done')
tag=event.getTagPath().toString()
system.tag.write(tag,False)
You are redefining python's built-in name list
as a local variable. That might be contributing.
Whoops-changed that and testing.
Still runs once then unable to find module.
Is this defined in the project library or in an event script? If its not in a project library script, try defining it in one, moving the import statements to outside of the function definition like so:
import os
from ftplib import FTP
import ftplib
def someFtpActionFunction():
""" """
# Your ftp stuff here
Also, someone more knowledgeable on me than this, could the from ftplib import FTP
followed by the import ftplib
cause any issues?
1 Like
Implementing as a project library seems to be working, thanks!
1 Like