473,383 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

ftplib question: how to upload files?

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.
Jul 18 '05 #1
3 19810
On Thu, 11 Sep 2003 14:35:32 -0400 (EDT), py****@sarcastic-horse.com
wrote:

What do I do to send files?


I use this:

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

-PU

Jul 18 '05 #2
<py****@sarcastic-horse.com> wrote in message
news:ma**********************************@python.o rg...
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(2048)
fd.seek(0, 0)
if temp.find('\0') != -1:
conn.storbinary(command, fd)
else:
conn.storlines(command, fd)
fd.close()

Anthony McDonald
Jul 18 '05 #3
<py****@sarcastic-horse.com> wrote in message
news:ma**********************************@python.o rg...
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/

Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Tommy | last post by:
Hi How do I upload files to a remote server from inside VS NET 2003? E.g. if I want to add files to an existing site on the remote server? I hope somebody can help TIA Tommy
1
by: Virginia | last post by:
Hello, For ASP.NET, can it upload files from the client server to another server(not this web server)? Or does it have any other way to do it? Maybe .NET Application, or Web Services? ...
2
by: Jim Lewis | last post by:
I need to upload files to a Web server from Flash MX. Flash does not have the ability to upload files. I have an example that uses a PHP page in the back ground to upload files...
2
by: Tom Wells | last post by:
I have a little file upload page that I have been able to use to successfully upload files to the C: drive of LocalHost (my machine). I need to be able to upload to a network drive from the intranet...
6
by: leandra_s | last post by:
Hello I want to upload files to a server with asp. But the problem is that the server where my asp website stands is a different server then where my upload files must go. Is there a way to...
21
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Uploading files from a local computer to a remote web server has many useful purposes, the most...
1
by: avias | last post by:
Hi All, Could anyone please help me with this:- I am developing a web application using asp.net and I want to upload files automatically from the client to server. The paths(directory...
2
by: karthickdevi | last post by:
Hi, I am developing a Desktop Application in VB .Net to upload files to the server. I need to encrypt the contents and upload it to the server. I am supposed to use enctype=multipart/form-data...
3
by: mp33487 | last post by:
I'm trying to upload/download files programmaticly to a records management system. I have it working fine on my dev machine using vb.net code-behind pages but when I place it on the server when it...
1
by: chirag narula | last post by:
Hello, I am working on a site currently. And I did make it live but I had to put it off due to this problem I found. I saw other threads with kind of same problem as well but nothing seems to solve...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.