[Pythonmac-SIG] FTPing a mac file - loosing resource fork?
Chris,Mann
cmann@pobox.com
Fri, 23 Apr 1999 07:56:53 -0400
Hello -
I've just started using python, and the first thing I'm trying to do is
write a little script that retrieves a mac file from an FTP site (it's
actually a .sea file).
Just when I thought I had everything working, I ran into a bit of a
snag. I'm using the provided ftplib and everything seems to work fine,
except that the file looses it's resource fork. Any ideas what I'm doing
wrong?
Here's the code (ftp_site is a dictionary of values that I pass in):
def get_remote(self, ftp_site):
# open a local file so we have something to write the ftp data to
fileID = open(ftp_site['localdir'] + ftp_site['file'] , 'wb')
from ftplib import FTP
print 'Retrieving ' + ftp_site['file'] + ' to ' + ftp_site['localdir']
# open the site, set pasv transfer mode, and login
ftp = FTP(ftp_site['host'])
ftp.set_pasv(ftp_site['pasv'])
ftp.login(ftp_site['user'], ftp_site['password'])
# change to correct dir, check size, and retrieve
ftp.cwd(ftp_site['remotedir'])
if ftp.size(ftp_site['file']) <= 1000: # know file is always greater then
a meg
print 'The file appears to be corrupted'
ftp.retrbinary('RETR ' + ftp_site['file'], fileID.write, 1024)
# cleanup
fileID.close()
ftp.close()
Also, is there a module to decode stuffit compressed files? I had thought
about wrapping the stuffit expander OSAX into a module, but that seems a bit
roundabout.
thanks
-chris