uploading a binary file with ftplib
maxm
maxm at normik.dk
Tue Mar 7 10:00:51 EST 2000
Maybe this function can be of some help?
###########
def FTP_GLOB_transfer(URL, TargetDir, UserName, Password, GlobExpression):
ftp = FTP(URL) # connect to host, default port
ftp.login(UserName,Password)
ftp.cwd(TargetDir)
FileTransferList = glob.glob(GlobExpression)
print URL, TargetDir, UserName, Password, GlobExpression
for file in FileTransferList:
FileName = file[-8:]
print file
TheFile = open(file, 'r')
ftp.storbinary('STOR ' + FileName, TheFile, 1024)
TheFile.close()
ftp.quit()
ftp = None
###########
-ly y'rs
Max M
------------------------------------------------------------------------
Max M Rasmussen, New Media Director http://www.normik.dk Denmark
e-mail mailto:maxm at normik.dk private mailto:maxmcorp at worldonline.dk
> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of thehaas at my-deja.com
> Sent: 7. marts 2000 05:20
> To: python-list at python.org
> Subject: uploading a binary file with ftplib
>
>
>
>
> I've submitted this to python.faqts.com, but no one has answered. So
> I'm asking it here. . .
>
> I'm trying to upload a binary file to a site using ftplib. I can log in
> successfully and do "cd dir_name", but cannot figure out how to upload
> the file. The standard Python module documentation seems a bit cryptic
> to me in this case (though it is usually quite good). This is the
> command I have used:
>
> ftp.storbinary('stor ravine.pyc',open('ravine.pyc','r').read(),2)
>
> And this is my result:
>
> Traceback (innermost last):
> File "<stdin>", line 1, in ?
> File "/usr/lib/python1.5/ftplib.py", line 366, in storbinary
> buf = fp.read(blocksize)
> AttributeError: 'string' object has no attribute 'read'
>
> Anyone have any insight?
>
> Thanks a lot,
>
> - mikeh
>
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
> --
> http://www.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list