Skip to content

Commit 54cdaf5

Browse files
committed
Making the script a lot more secure
Removing the need for a text file with settings stored in it. Instead store everything in the python file, and ask for username/password at launch modified: FTP.py modified: README.md
1 parent e6b8cf2 commit 54cdaf5

File tree

2 files changed

+19
-40
lines changed

2 files changed

+19
-40
lines changed

FTP.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,17 @@
44
@author: robbie
55
'''
66
from ftplib import FTP
7-
import os, sys, subprocess
7+
import os, sys, subprocess, getpass
88

9-
REMOTE_ROOT = "./" # Changed in settings file
109
TRUNK = "trunk/"
1110
ADDED = "A "
1211
DELETED = "D "
1312
UPDATED = "U "
1413
OFFSET = len(ADDED) + len(TRUNK)
15-
SETTINGS_FILE = "E:\website.txt"
14+
15+
LOCAL = "C:\\My Site"
16+
FTP_SERVER = "mysite.example.com"
17+
REMOTE_ROOT = "public_html/"
1618

1719
def upload(ftp, local_root, files):
1820
for file_name in files:
@@ -82,14 +84,10 @@ def delete(ftp, files):
8284
if repo == "" or rev == "":
8385
raise Exception("Empty repo or rev")
8486

85-
with open(SETTINGS_FILE, "r") as settings:
86-
local = settings.readline().rstrip()
87-
ftp_server = settings.readline().rstrip()
88-
user = settings.readline().rstrip()
89-
password = settings.readline().rstrip()
90-
REMOTE_ROOT = settings.readline().rstrip()
87+
user = raw_input("Please enter your ftp username: ")
88+
password = getpass.getpass()
9189

92-
local_root = os.path.join(local, TRUNK)
90+
local_root = os.path.join(LOCAL, TRUNK)
9391

9492
# Take SVN changed output and convert it to a list of Added/Deleted/Modified
9593
changed = subprocess.check_output(["svnlook", "changed", "-r", rev, repo]).split("\r\n")[:-1]
@@ -106,7 +104,7 @@ def delete(ftp, files):
106104
elif change.startswith(UPDATED):
107105
updated.append(file_name)
108106

109-
ftp = FTP(ftp_server)
107+
ftp = FTP(FTP_SERVER)
110108
ftp.login(user, password)
111109

112110
print "Adding new files to FTP"

README.md

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,23 @@
11
svn2ftp
22
=======
3-
## Purpose
4-
### Short Story
5-
This Python script automatically uploads SVN commits to a specified FTP location.
6-
7-
### Long Story
3+
## Features
84
When converting my website to SVN, I wanted a tool to allow me to avoid manually
9-
uploading changes to my FTP server. I found some solutions online, but most of
5+
uploading commit changes to my FTP server. I found some solutions online, but most of
106
them weren't exactly what I was looking for, and many were too complicated.
11-
127
I ended up making something from scratch using the changelist provided by SVN.
13-
I had to figure out how to pass it the sensitive user information. I decided
14-
to use a local file which the script would use to extract what it needed.
15-
While it's not the most secure solution, it was good enough for my needs.
16-
Feel free to fork this project and implement your own way of passing the ftp information.
17-
An example solution could be to prompt the user each time a commit is pushed.
8+
9+
This tool automatically uploads all new and modified files to the server, and deletes
10+
any file or folder that was removed from the SVN repo. The script runs when a commit completes.
1811

1912
## Installation
2013
This script is very simple to install.
2114

2215
1. Copy post-commit.bat and FTP.py to your svn\hooks\ folder.
23-
2. Create a file that will contain the necessary FTP server information (each item should be on its own line, in the following order):
24-
- The full path location to the local SVN repo
25-
- The full URL to the FTP server
26-
- The username for the FTP server
27-
- The password for the FTP server
28-
- The root directory to upload the repo to (default should be './')
29-
3. Modify FTP.py's SETTINGS_FILE variable to the full location of this file
30-
4. Make a commit and see the script run.
31-
32-
### Example settings file
33-
<pre>
34-
E:\mysite
35-
robbie.ftpserver.org
36-
robbie
37-
thepassword
38-
public_html/
39-
</pre>
16+
2. Modify the following varaibles in FTP.py
17+
- LOCAL - The full path location to the local SVN repo
18+
- FTP_SERVER - The full URL to the FTP server
19+
- REMOTE_ROOT - The root directory to upload the repo to
20+
3. Make a commit, enter your username and password, and see the script run.
4021

4122
## TODO
4223
- Modify post-commit.bat so the command prompt closes automatically

0 commit comments

Comments
 (0)