Skip to main content
Trying to copy an SQL file to an external FTP site. Using FME 2013.

 

 

Here is the script:

import fmeobjects

 

import ftplib

 

import os

 

import glob

# FTP Section

 

print 'Connecting to FTP Site...'

# Connect to FTP site 

 

s = ftplib.FTP('ftpsite','city@ftpsite','password')

# Point to file to send

 

f = open('Z:\\DataExport\\FME\\Other_Exports\\Export\\REALTY_LISTINGS_DATA_test.SQL','r')               

# Send the file to FTP site

 

print 'Sending file...'

 

s.storbinary('REALTY_LISTINGS_DATA_test.SQL', f)

print 'Finished Sending file.'

# Close file and FTP connection

 

f.close()                      

 

s.quit()

 

 

I'm getting the following error, why?

Python Exception <error_perm>: 500 ?

 

Error executing string `import fmeobjects

 

 

I am assuming Python is installed with FME. Do I have to do something else to make this work. Never used Python before. Copied most of this from a sample.

 

 

Thanks.

 

 

 
Hi,

 

 

Are using this script as a shutdown script?

 

According to this shutdown or start up scripts cannot make use of fme objects.

 

" However, the scripts can start new processes via the "exec" command (Tcl), and these new processes could involve FME Objects Tcl without any conflict."

 

 

Could also be a simple python error, that not surprisingly eludes me and my basic knoledge of python.....

 

 

Hope this hepls.

 

 


Yes, this is a shutdown script. So if I remove the line

 

import fmeobjects

 

I then get the error:

 

Python Exception <error_perm>: 500 ?

Error executing string `import ftplib

 

 

 


Can't comment on the Python script, but if you can't use a shutdown script with FMEObjects as Itay says, could you use a Python caller in the Workbench using a Creator to initiate it by setting the Creator option 'create at end' = yes ?
Hi,

 

 

there is no problem referencing objects in the "fmeobjects" module in general from shutdown scripts, ref this post I made three days ago. (It has been tested and verified in FME 2012 and 2013).

 

 

The fmepedia article that Itay linked to needs some attention from Safe as it is quite unclear about this. My guess is that you cannot access FME feature objects in a shutdown script (which makes perfect sense), but someone from Safe ought to verify this.

 

 

As for the original poster's problems: I have never seen this error before. I would recommend that you reinstall FME to see if it helps. Also, verify that you have all the sufficient permissions on your computer. Perhaps try logging on with local administrator privileges to isolate this particular issue.

 

 

David
Hi again,

 

 

I researched your problem a bit further and it seems that the exception "error_perm" comes from the ftplib module.

 

 

Since you are sending your file with a binary mode transfer (storbinary), you will probably also have to open it in binary mode.

 

 

Try replacing your line f = open('filename.SQL','r') with f = open('filename.SQL','rb')

 

Let us know how it works out.

 

 

David

 

 

 


Just to confirm,

 

Yes you can use FME Objects in Python Shutdown scripts. Starting in FME 2012 you would use

 

import fmeobjects

 

 

I made a quick edit to the article Itay referenced but this article is slated for further work in the near future.
OK, I finally figured this out and now have it running on FME Server.

 

 

Here is the final, working script:

import ftplib

 

import os

 

import time

# Connect to FTP site

 

ftp = ftplib.FTP('ftpsitename')

 

ftp.login ('ftpusername','ftppassword')

 

 

# Declare the directory and filename. The current date is appended to the filename of each day's export so I only need to FTP the most current file.

 

dir = 'C:\\ExportedData\\Apps'

 

fname = 'REALTY_LISTINGS_DATA_' + time.strftime('%Y%m%d') + '.SQL'

# Point to file to send and send as binary.

 

ftp.storbinary('STOR ' + fname, open(dir + '\\\\' + fname, 'rb'))

 

# Close the FTP connection

 

ftp.close

Python is not very user friendly. :-(

 


Reply