Created
March 6, 2018 00:41
-
-
Save kspillane/c1c05fd7bd27fd1677e49ca1b485da0e to your computer and use it in GitHub Desktop.
A python script for uploading a file to multiple FTP servers sequentially
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys, os | |
from ftplib import FTP | |
username = str(raw_input("FTP Server Username: ")) | |
password = str(raw_input("FTP Server Password: ")) | |
srvfile = str(raw_input("Server list file?: ")) | |
try: | |
f = open(srvfile) | |
except IOError: | |
print("There was an error reading your file - "+srvfile) | |
raw_input() | |
sys.exit() | |
else: | |
with f: | |
serverlist = [line.rstrip('\n') for line in f] | |
datfile = str(raw_input("Data file to send?: ")) | |
try: | |
basepath, datfilename = os.path.split(datfile) | |
except IOError: | |
print("There was an error reading your file - "+datfile) | |
raw_input() | |
sys.exit() | |
else: | |
count = 0 | |
for server in serverlist: | |
try: | |
ftp = FTP(server) | |
except socket.error: | |
print("There was an error connecting to server " + server) | |
raw_input("Press any key to exit...") | |
sys.exit() | |
else: | |
ftp.login(username, password) | |
try: | |
fp = open(datfile, "rb") | |
ftp.storbinary("STOR " + datfilename, fp) | |
fp.close() | |
ftp.quit() | |
ftp.close() | |
except IOError: | |
print("There was an error storing the file!") | |
raw_input("Press any key to exit...") | |
sys.exit() | |
else: | |
print("Stored file "+ datfilename + " on " + server) | |
count += 1 | |
print("") | |
print("Files stored at /home/jhasupport") | |
print("Sent to " + str(count) + " servers.") | |
print("Remember to adjust the file permissions!") | |
print("") | |
raw_input("Press any key to exit...") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment