Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ftplib question: how to upload files?

Reply
Thread Tools

ftplib question: how to upload files?

 
 
python@sarcastic-horse.com
Guest
Posts: n/a
 
      09-11-2003
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:
>>>import ftplib
>>>conn = ftplib.FTP('ftp.example.com')
>>>conn.login(user='userid', passwd='passwd')
>>>conn.cwd('/var/www/html/incoming')


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.


 
Reply With Quote
 
 
 
 
Patrick Useldinger
Guest
Posts: n/a
 
      09-11-2003
On Thu, 11 Sep 2003 14:35:32 -0400 (EDT), http://www.velocityreviews.com/forums/(E-Mail Removed)
wrote:


>What do I do to send files?


I use this:

f=file(fileName,'rb')
conn.storbinary('STOR '+os.path.basename(fileName),f)

-PU

 
Reply With Quote
 
 
 
 
Anthony McDonald
Guest
Posts: n/a
 
      09-11-2003
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:
> >>>import ftplib
> >>>conn = ftplib.FTP('ftp.example.com')
> >>>conn.login(user='userid', passwd='passwd')
> >>>conn.cwd('/var/www/html/incoming')

>
> 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(204
fd.seek(0, 0)
if temp.find('\0') != -1:
conn.storbinary(command, fd)
else:
conn.storlines(command, fd)
fd.close()

Anthony McDonald


 
Reply With Quote
 
Steve Holden
Guest
Posts: n/a
 
      09-12-2003
<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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:
> >>>import ftplib
> >>>conn = ftplib.FTP('ftp.example.com')
> >>>conn.login(user='userid', passwd='passwd')
> >>>conn.cwd('/var/www/html/incoming')

>
> 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
--
Steve Holden http://www.holdenweb.com/
Python Web Programming http://pydish.holdenweb.com/pwp/



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Sending file to print server using ftplib Joshua Burvill Python 0 05-20-2004 01:40 AM
Having trouble extracting useful directory details from ftplib.FTP Stephen Horne Python 2 02-22-2004 06:19 AM
Uploading a file with ftplib Michael_Goettsche Python 2 01-01-2004 02:56 PM
ftplib storbinary with timeout on windows Gerrit Holl Python 0 12-29-2003 09:19 AM



Advertisments