By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,957 Members | 1,936 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,957 IT Pros & Developers. It's quick & easy.

Help implementing an idea

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
Take a look at: http://dirssync.sourceforge.net/

See if that gives you any direction.

Jul 19 '05 #2

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.