Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Help implementing an idea

Reply
Thread Tools

Help implementing an idea

 
 
Nicholas.Vaidyanathan@asu.edu
Guest
Posts: n/a
 
      06-17-2005
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?
 
Reply With Quote
 
 
 
 
utabintarbo@gmail.com
Guest
Posts: n/a
 
      06-17-2005
Take a look at: http://dirssync.sourceforge.net/

See if that gives you any direction.

 
Reply With Quote
 
 
 
 
rh0dium
Guest
Posts: n/a
 
      06-17-2005
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

 
Reply With Quote
 
Tim Roberts
Guest
Posts: n/a
 
      06-19-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
>
>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 ,


Or sys.stdout.writelines( lines ).

>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?


How do you want to do the upload? FTP? That's easy. Check ftplib.py.
--
- Tim Roberts, (E-Mail Removed)
Providenza & Boekelheide, Inc.
 
Reply With Quote
 
gene tani
Guest
Posts: n/a
 
      06-19-2005
http://aspn.activestate.com/ASPN/Coo.../Recipe/299271

or the nice recipe, page 403 of cookbook2, that i can't find in ASPN

 
Reply With Quote
 
Fuzzyman
Guest
Posts: n/a
 
      06-19-2005
(E-Mail Removed) wrote:
[snip..]
> 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?


Upload to a URL *sounds* like you want to do the upload by http rather
than ftp.

In this case you can do it with a Python CGI on the server and a script
on the client that communicates with the CGI.

When voidspace is back up you can find a pair of scripts that do just
that :

http://www.voidspace.org.uk/python/cgi.shtml#upload

Hint - filelist = [os.path.join(directory, entry) for entry in
os.listdir(directory)]

Regards,

Fuzzy
http://www.voidspace.org.uk/python

 
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: App idea, Any idea on implementation? Matthew_WARREN@bnpparibas.com Python 0 02-05-2008 05:50 PM
App idea, Any idea on implementation? Dr Mephesto Python 3 02-05-2008 06:55 AM
Re: Thoughts on implementing this idea Andrew Pressel Perl 0 07-30-2006 02:40 PM
Nested conditional expressions ---- good idea/bad idea? nimmi_srivastav@yahoo.com C Programming 10 02-02-2005 10:51 PM
Need help implementing a proj on SPARTAN3 Riccardo Fregonese VHDL 2 01-03-2005 01:21 PM



Advertisments