473,414 Members | 1,744 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,414 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 19811
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.