ftp upload with urllib or ftplib?

Stephen Reiach sreich at fit.edu
Sat Dec 8 20:06:05 EST 2001

>It it possible to _upload_ a file using urllib? E.g. to post
>the file contents, the username, and the password in the 'data',
>or something?

I think what you want to use is ftplib something like this:

import ftplib
ftp = ftplib.FTP("ftp.site.com")
ftp.login("username", "password")
#for text files
filename ="somefile.txt"
ftp.storlines("STOR " + filename, open(filename))
#for binary
filename ="somefile.exe"
ftp.storbinary("STOR " + filename, open(filename, "rb"), 1024)

Stephen R

More information about the Python-list mailing list