ftplib question: how to upload files?

P

python

Hi:

I want to write a procedure to automatically upload some files for me, but
I'm getting stuck. Before I write my own gruesome put() function, I
wanted to check if there is an easier way.

Here's what I can do so far:
What do I do to send files?

I have three files I want to upload, but I'm not sure what to do. I hoped
to find a ftplib.put() method, but it looks like ftplib is a low-level
interface.

All help is welcome.
 
A

Anthony McDonald

Hi:

I want to write a procedure to automatically upload some files for me, but
I'm getting stuck. Before I write my own gruesome put() function, I
wanted to check if there is an easier way.

Here's what I can do so far:

What do I do to send files?

I have three files I want to upload, but I'm not sure what to do. I hoped
to find a ftplib.put() method, but it looks like ftplib is a low-level
interface.

All help is welcome.
The methods your searching for are storlines (for ascii) or storbinary (for
non ascii).

You can simplyfy the process slightly with your own wrapper to those 2
methods to guess the file mode and call the correct method with the STOR
command created for you. An example is below.

def upload(conn, fname):
(head, tail) = os.path.split(fname)
command = "STOR " + tail
fd = open(fname, 'rb')
temp = fd.read(2048)
fd.seek(0, 0)
if temp.find('\0') != -1:
conn.storbinary(command, fd)
else:
conn.storlines(command, fd)
fd.close()

Anthony McDonald
 
S

Steve Holden

Hi:

I want to write a procedure to automatically upload some files for me, but
I'm getting stuck. Before I write my own gruesome put() function, I
wanted to check if there is an easier way.

Here's what I can do so far:

What do I do to send files?

I have three files I want to upload, but I'm not sure what to do. I hoped
to find a ftplib.put() method, but it looks like ftplib is a low-level
interface.

All help is welcome.

See if the code in

http://www.holdenweb.com/Python/PDCode/ftpStream.py

will help. It's supposed to make FTP easier.

regards
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top