473,413 Members | 2,058 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,413 software developers and data experts.

Help implementing an idea

Well, I'm a total python n00b, but I was playing around with exception handling
yesterday, and was stricken by how incredibly easy it is to use the op system
to create nice scripts... I did the following:

import sys
lines = sys.stdin.readlines()
lines.sort()
for stuff in lines:
print stuff ,

just to copy stuff from one file to another, and was quite impressed with the
results. Now, I was thinking today, I'd really like to create a program that
can go to a specific directory and upload all the files in the directory to a
specific url for backup purposes, and I have the feeling that the python
implementation would be ruthlessly small and efficient, like the
above....anyone who could point me in the right direction as to how to actually
do it?
Jul 19 '05 #1
2 1236
Take a look at: http://dirssync.sourceforge.net/

See if that gives you any direction.

Jul 19 '05 #2
Try this..
#!/usr/bin/env python
# Upload a file to a FTP server

from sys import argv, exit
from ftplib import FTP

if len(argv) != 6:
print 'Incorrect number of parameters'
print 'USAGE: upload.py <server> <username> <password> <local
file>
<remote file>'
exit(0)

server = argv[1]
username = argv[2]
password = argv[3]
upfile = argv[5]
downfile = argv[4]

try:
print 'Connecting to %s' % server
ftp = FTP(server)
ftp.login(username, password)
print 'Connection to %s opened' % server
#send file in binary mode to server (STOR command sets remote
filename)
ftp.storbinary('STOR %s' % upfile, open(downfile,'r'))
ftp.quit()
print 'File %s uploaded' % upfile
except Exception, err:
print 'Error uploading file. Error: %s' % err

Jul 19 '05 #3

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

Similar topics

6
by: Steven D'Aprano | last post by:
I've been working with the Borg design pattern from here: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66531 and I'm having problems subclassing it. I'm a newbie, so I've probably...
5
by: Rob Forey -- The Man With No Nails | last post by:
Hi, I'm new to databases & asp and am using dreamweaver mx 2004 (trial) to go about making dynamic pages. I was wondering if anyone could help me with a problem that I'm having, I would think...
1
by: Devon | last post by:
Hi, I'm just getting my feet wet with C# and need some help with interface implementation. I want to create a collection of various objects that implement a certain interface (i.e. IMyInterface)....
6
by: Index | last post by:
Hi, I have a file which I want to sort depending on multiple columns. Actually I want to implement the following query through programming: SELECT SUM(VALUES) GROUP BY x,y ORDER BY x,y; the...
4
by: phl | last post by:
hi, My question is: 1. To avoid possible memory leaks, when you use this pattern, after you have dealth with the unmanaged resources and before you take your object off the finalize queue,...
3
by: Matthew Warren | last post by:
I have the following piece of code, taken from a bigger module, that even as I was writing I _knew_ there were better ways of doing it, using a parser or somesuch at least, but learning how wasn't...
9
by: raylopez99 | last post by:
What's the best way of implementing a multi-node tree in C++? What I'm trying to do is traverse a tree of possible chess moves given an intial position (at the root of the tree). Since every...
4
by: Mohamed Mansour | last post by:
Hello, What is the purpose of implementing the Observer Pattern if we can trigger an event easily? For example (from books), You have a "Forecaster" which notifies "Observable" when a...
2
by: ahmadoubay_20240 | last post by:
The assignment aims at enforcing the encryption and communication techniques. It helps the student in acquiring the necessary knowledge in developing client/server application and in securing...
68
by: zwsdotcom | last post by:
I've been looking for references for some weeks now, but haven't found an answer to the following question. I'd love some help on this: *Without* using JavaScript or other active client-side...
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
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...
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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.