From ed54ce95a79ac22951c2ffe8ce319fdfb16e8680 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 16:32:50 -0700 Subject: [PATCH 01/21] Update sric_script.py Switches to FTP, and adds a bunch of comments for things we still need to do... --- sric_script.py | 53 +++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/sric_script.py b/sric_script.py index 93cb81a..cbdbfdd 100644 --- a/sric_script.py +++ b/sric_script.py @@ -1,14 +1,23 @@ import subprocess +from ftplib import FTP # I'd rather use ftputil, since it's a nice wrapper for ftplib, but it might make things slower? from Modules.file_parse.__file_parse__ import obt_login from Modules.file_parse.__file_parse__ import obt_pass from Modules.file_parse.__file_parse__ import obt_message +# Could we replace this with: +# import Modules.file_parse +# ? # The IP of the server we're downloading/uploading things to/from server = 192.168.1.1 +ftp_addr = server +# ftp_addr = 'ftp://' + server # The names of the files were dealing with -creds = 'credentials.txt' -upload = 'upload-package.txt' +creds_file = open('credentials.txt', 'wb') +upload = open('upload_package.txt', 'r') + +# Where we want to put the file +upload_name = 'tmp-dicks' # Download creds down_user = 'tmp' @@ -19,37 +28,49 @@ up_pass = 'tmp' up_mess = 'tmp' +# Set up the FTP object +FTP.set_debuglevel(2) + +# Can we use this to remove the network connection test? +#ftp = FTP() +#ftp.connect(ftp_addr, timeout=1) + # Loop forever! while True: # Verify connection - output = subprocess.check_output(['ping', '-n', '1', server]) + # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s + output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... if output = 'tmp string for network down': continue - # Using SFPT because I'm not sure if we can use SCP - with pysftp.Connection('http://' + server, username = down_user, password = down_pass) as sftp: - # Get the download payload - sftp.get(creds, '/creds.txt') - - # Open download file - cred_file = open(creds) + # connect to the FTP object and Login anonymously + ftp = FTP(ftp_addr) + ftp.login() + + # Change directory if needed + #ftp.cwd() + + # Need to do more testing with this line, we might be able to just use storelines or retrlines... + ftp.retrbinart('RETR ', creds_file.write) # Parse it mytext reads all lines of the file contents # up_usr and up_pass defined in file contents - text = cred_file.readlines() + text = creds_file.readlines() up_user = obt_login(text) up_pass = obt_pass(text) up_mess = obt_message(text) - with pysftp.Connection(server, username = up_user, password = up_pass) as sftp: - # Put the upload payload - sftp.put(uplpad) + # Login with the new creds and put the file + ftp.login(up_user, up_pass) + ftp.storelines('STOR', upload_name, upload) + - # Close cred_file (After the put since we need to get that done as fast as possible) + # Close files (After the put since we need to get that done as fast as possible) cred_file.close() + uplaod.close() # End this script to save resources for other things break - # Not currently connected... Time to try again +# Not currently connected... Time to try again From 1071448032c8a56fd452740c60a69a9194608b02 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 16:33:39 -0700 Subject: [PATCH 02/21] Update sric_script.py Deletes unused variables. We don't need to instantiate up_* vars before using them. --- sric_script.py | 9 --------- 1 file changed, 9 deletions(-) diff --git a/sric_script.py b/sric_script.py index cbdbfdd..26159bc 100644 --- a/sric_script.py +++ b/sric_script.py @@ -19,15 +19,6 @@ # Where we want to put the file upload_name = 'tmp-dicks' -# Download creds -down_user = 'tmp' -down_pass = 'tmp' - -# Upload Creds -up_user = 'tmp' -up_pass = 'tmp' -up_mess = 'tmp' - # Set up the FTP object FTP.set_debuglevel(2) From 2fa9d817c6a221bd12d65e85445e00826d6c7cd8 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 16:43:19 -0700 Subject: [PATCH 03/21] Update sample.txt Removed whitespace. We should probably run the test again. --- Modules/file_parse/sample.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Modules/file_parse/sample.txt b/Modules/file_parse/sample.txt index 5309366..4547618 100644 --- a/Modules/file_parse/sample.txt +++ b/Modules/file_parse/sample.txt @@ -1,3 +1,2 @@ - login, pass - +login, pass This is a messsage From b4e053ab5a2eeeeb370a562f1445be4c75c0ad11 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 16:57:28 -0700 Subject: [PATCH 04/21] Update sric_script.py Cleans things up a little better. --- sric_script.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sric_script.py b/sric_script.py index 26159bc..4061fed 100644 --- a/sric_script.py +++ b/sric_script.py @@ -57,11 +57,10 @@ ftp.login(up_user, up_pass) ftp.storelines('STOR', upload_name, upload) - - # Close files (After the put since we need to get that done as fast as possible) + # End this script to save resources for other things + ftp.quit() cred_file.close() uplaod.close() - # End this script to save resources for other things break # Not currently connected... Time to try again From 52c89778db9d0bdaa0ccb41ac136d1de576d64c6 Mon Sep 17 00:00:00 2001 From: David Kroell Date: Tue, 9 Jun 2015 22:13:21 -0400 Subject: [PATCH 05/21] updating modules based on new sample format --- Modules/file_parse/__file_parse__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Modules/file_parse/__file_parse__.py b/Modules/file_parse/__file_parse__.py index 32f3975..8006b8e 100644 --- a/Modules/file_parse/__file_parse__.py +++ b/Modules/file_parse/__file_parse__.py @@ -7,7 +7,7 @@ def obt_login(text): first_line = text[0] line_list = first_line.split(',') #indentation can cause an error - return line_list[0].replace(" ", "") + return line_list[0].replace(" ", "") def obt_pass(text): first_line = text[0] @@ -15,7 +15,7 @@ def obt_pass(text): return line_list[1].replace(" ", "") def obt_message(text): - mess_line = text[2] + mess_line = text[1] return mess_line From 800e7da48b8a3746904c9aaed872c844539ad319 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 19:12:41 -0700 Subject: [PATCH 06/21] Update sric_script.py Removes a comment about ftp_addr creation. --- sric_script.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sric_script.py b/sric_script.py index 4061fed..c738880 100644 --- a/sric_script.py +++ b/sric_script.py @@ -8,9 +8,7 @@ # ? # The IP of the server we're downloading/uploading things to/from -server = 192.168.1.1 -ftp_addr = server -# ftp_addr = 'ftp://' + server +ftp_addr = 192.168.1.1 # The names of the files were dealing with creds_file = open('credentials.txt', 'wb') From d935988e33be20f5a591a51bbed4153791592a5e Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 19:13:02 -0700 Subject: [PATCH 07/21] Update sric_script.py --- sric_script.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/sric_script.py b/sric_script.py index c738880..6ce2a32 100644 --- a/sric_script.py +++ b/sric_script.py @@ -3,9 +3,6 @@ from Modules.file_parse.__file_parse__ import obt_login from Modules.file_parse.__file_parse__ import obt_pass from Modules.file_parse.__file_parse__ import obt_message -# Could we replace this with: -# import Modules.file_parse -# ? # The IP of the server we're downloading/uploading things to/from ftp_addr = 192.168.1.1 From 6d8d62559f5f68599d80de4bca61270de845e480 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 19:20:31 -0700 Subject: [PATCH 08/21] Update sric_script.py --- sric_script.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/sric_script.py b/sric_script.py index 6ce2a32..b9c7953 100644 --- a/sric_script.py +++ b/sric_script.py @@ -17,17 +17,18 @@ # Set up the FTP object FTP.set_debuglevel(2) -# Can we use this to remove the network connection test? -#ftp = FTP() -#ftp.connect(ftp_addr, timeout=1) - # Loop forever! while True: - # Verify connection - # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s - output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... - if output = 'tmp string for network down': +# # Verify connection +# # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s +# output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... +# if output = 'tmp string for network down': +# continue + + try: + ftp = FTP(ftp_addr, timeout = 1) + except: # What exception ftp.connect will raise for a timeout error? continue # connect to the FTP object and Login anonymously From c003d2f6c2ec7b4d9c666934b8fb2afc8d7056eb Mon Sep 17 00:00:00 2001 From: David Kroell Date: Tue, 9 Jun 2015 22:41:36 -0400 Subject: [PATCH 09/21] updating module testing efficiency for file parsing module --- Modules/file_parse/README.md | 10 ++++++++++ Modules/file_parse/__file_parse__.py | 4 +++- Modules/file_parse/__init__.py | 0 Modules/file_parse/{ => testfiles}/sample.txt | 0 Modules/file_parse/testfiles/sample1.txt | 2 ++ 5 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 Modules/file_parse/README.md create mode 100644 Modules/file_parse/__init__.py rename Modules/file_parse/{ => testfiles}/sample.txt (100%) create mode 100644 Modules/file_parse/testfiles/sample1.txt diff --git a/Modules/file_parse/README.md b/Modules/file_parse/README.md new file mode 100644 index 0000000..eec68ba --- /dev/null +++ b/Modules/file_parse/README.md @@ -0,0 +1,10 @@ + + +# Parsing Module + +File Parsing +=========== + +This module helps us extract credential files from text files that are taken by the information center. + +Inorder to run a testfile choose one of the files in the testfiles folder and run the python script with the filename and extension after it. This would be such as testing the extraction of credentials from the file sample.txt by running: `python __file_parse__.py sample.txt` \ No newline at end of file diff --git a/Modules/file_parse/__file_parse__.py b/Modules/file_parse/__file_parse__.py index 8006b8e..c68d501 100644 --- a/Modules/file_parse/__file_parse__.py +++ b/Modules/file_parse/__file_parse__.py @@ -1,4 +1,6 @@ +import sys + #methods for obtaining credentials from a sample file. #The paramemter passed is the file itself once opened. #these methods are based on the sample of how the credentials will be sent remotely. @@ -20,7 +22,7 @@ def obt_message(text): #file concatination: -file = open("sample.txt") +file = open('testfiles/'+sys.argv[1]) text = file.readlines() #Printing the test file credentials diff --git a/Modules/file_parse/__init__.py b/Modules/file_parse/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/Modules/file_parse/sample.txt b/Modules/file_parse/testfiles/sample.txt similarity index 100% rename from Modules/file_parse/sample.txt rename to Modules/file_parse/testfiles/sample.txt diff --git a/Modules/file_parse/testfiles/sample1.txt b/Modules/file_parse/testfiles/sample1.txt new file mode 100644 index 0000000..475e9c5 --- /dev/null +++ b/Modules/file_parse/testfiles/sample1.txt @@ -0,0 +1,2 @@ +usr,1234 +Hello World From 1e6e475d3420ac4da0ee7b030fd389bf4570061f Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 20:29:10 -0700 Subject: [PATCH 10/21] Update sric_script.py Correct error handling --- sric_script.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sric_script.py b/sric_script.py index b9c7953..ff1f14e 100644 --- a/sric_script.py +++ b/sric_script.py @@ -28,7 +28,8 @@ try: ftp = FTP(ftp_addr, timeout = 1) - except: # What exception ftp.connect will raise for a timeout error? + except ftplib.all_errors, e: + print "FTP ERROR:", e continue # connect to the FTP object and Login anonymously From 7d649dce4918ed2eee1888efb211925494553de5 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 20:31:34 -0700 Subject: [PATCH 11/21] Update sric_script.py --- sric_script.py | 1 + 1 file changed, 1 insertion(+) diff --git a/sric_script.py b/sric_script.py index ff1f14e..8bdaf29 100644 --- a/sric_script.py +++ b/sric_script.py @@ -26,6 +26,7 @@ # if output = 'tmp string for network down': # continue + # We don't need to verify that we have a valid connection, because ftplib will do that for us. try: ftp = FTP(ftp_addr, timeout = 1) except ftplib.all_errors, e: From 505948887c7d5cb55cb14df5bbb820a4e929ab63 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 20:48:58 -0700 Subject: [PATCH 12/21] Update sric_script.py --- sric_script.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/sric_script.py b/sric_script.py index 8bdaf29..569a797 100644 --- a/sric_script.py +++ b/sric_script.py @@ -8,11 +8,13 @@ ftp_addr = 192.168.1.1 # The names of the files were dealing with -creds_file = open('credentials.txt', 'wb') +download = 'team1.txt' upload = open('upload_package.txt', 'r') +creds_file = open('credentials.txt', 'wb') # Where we want to put the file -upload_name = 'tmp-dicks' +upload_name = 'CNU/IMPRINT_upload_package.txt' +team_dir = 'auvsi/team1/' # Set up the FTP object FTP.set_debuglevel(2) @@ -38,10 +40,12 @@ ftp.login() # Change directory if needed - #ftp.cwd() + if team_dir: + ftp.cwd(team_dir) # Need to do more testing with this line, we might be able to just use storelines or retrlines... - ftp.retrbinart('RETR ', creds_file.write) + ftp.retrbinary('RETR', creds_file.write) + ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) # Parse it mytext reads all lines of the file contents # up_usr and up_pass defined in file contents From 7ee5acce5716b003889d34bcd69097b10d5ec902 Mon Sep 17 00:00:00 2001 From: David Kroell Date: Tue, 9 Jun 2015 23:54:18 -0400 Subject: [PATCH 13/21] uploading txt --- upload_package.txt | 1 + 1 file changed, 1 insertion(+) create mode 100644 upload_package.txt diff --git a/upload_package.txt b/upload_package.txt new file mode 100644 index 0000000..27efb2e --- /dev/null +++ b/upload_package.txt @@ -0,0 +1 @@ +CNU IMPRINT UAS - Upload Task SRIC From 1bf9d270e1c2639aea0db7515d07387e1858c209 Mon Sep 17 00:00:00 2001 From: David Kroell Date: Wed, 10 Jun 2015 00:03:09 -0400 Subject: [PATCH 14/21] making comment retrbinary --- sric_script.py | 2 +- sric_script.py~ | 68 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 sric_script.py~ diff --git a/sric_script.py b/sric_script.py index 569a797..7706ff8 100644 --- a/sric_script.py +++ b/sric_script.py @@ -44,7 +44,7 @@ ftp.cwd(team_dir) # Need to do more testing with this line, we might be able to just use storelines or retrlines... - ftp.retrbinary('RETR', creds_file.write) +# ftp.retrbinary('RETR', creds_file.write) ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) # Parse it mytext reads all lines of the file contents diff --git a/sric_script.py~ b/sric_script.py~ new file mode 100644 index 0000000..569a797 --- /dev/null +++ b/sric_script.py~ @@ -0,0 +1,68 @@ +import subprocess +from ftplib import FTP # I'd rather use ftputil, since it's a nice wrapper for ftplib, but it might make things slower? +from Modules.file_parse.__file_parse__ import obt_login +from Modules.file_parse.__file_parse__ import obt_pass +from Modules.file_parse.__file_parse__ import obt_message + +# The IP of the server we're downloading/uploading things to/from +ftp_addr = 192.168.1.1 + +# The names of the files were dealing with +download = 'team1.txt' +upload = open('upload_package.txt', 'r') +creds_file = open('credentials.txt', 'wb') + +# Where we want to put the file +upload_name = 'CNU/IMPRINT_upload_package.txt' +team_dir = 'auvsi/team1/' + +# Set up the FTP object +FTP.set_debuglevel(2) + +# Loop forever! +while True: + +# # Verify connection +# # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s +# output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... +# if output = 'tmp string for network down': +# continue + + # We don't need to verify that we have a valid connection, because ftplib will do that for us. + try: + ftp = FTP(ftp_addr, timeout = 1) + except ftplib.all_errors, e: + print "FTP ERROR:", e + continue + + # connect to the FTP object and Login anonymously + ftp = FTP(ftp_addr) + ftp.login() + + # Change directory if needed + if team_dir: + ftp.cwd(team_dir) + + # Need to do more testing with this line, we might be able to just use storelines or retrlines... + ftp.retrbinary('RETR', creds_file.write) + ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) + + # Parse it mytext reads all lines of the file contents + # up_usr and up_pass defined in file contents + text = creds_file.readlines() + + up_user = obt_login(text) + up_pass = obt_pass(text) + up_mess = obt_message(text) + + # Login with the new creds and put the file + ftp.login(up_user, up_pass) + ftp.storelines('STOR', upload_name, upload) + + # End this script to save resources for other things + ftp.quit() + cred_file.close() + uplaod.close() + break + +# Not currently connected... Time to try again From eb6669809d1daa62b7528b8a0d31b043ba20df50 Mon Sep 17 00:00:00 2001 From: tarrenj Date: Tue, 9 Jun 2015 20:54:08 -0700 Subject: [PATCH 15/21] Update sric_script.py Fixes typos --- sric_script.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/sric_script.py b/sric_script.py index 7706ff8..e59b65d 100644 --- a/sric_script.py +++ b/sric_script.py @@ -35,7 +35,7 @@ print "FTP ERROR:", e continue - # connect to the FTP object and Login anonymously + # Connect to the FTP object and Login anonymously ftp = FTP(ftp_addr) ftp.login() @@ -48,7 +48,6 @@ ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) # Parse it mytext reads all lines of the file contents - # up_usr and up_pass defined in file contents text = creds_file.readlines() up_user = obt_login(text) @@ -62,7 +61,7 @@ # End this script to save resources for other things ftp.quit() cred_file.close() - uplaod.close() + upload.close() break # Not currently connected... Time to try again From 1cca28f4327f1ffa517c790da8a024f7619c93d5 Mon Sep 17 00:00:00 2001 From: David Kroell Date: Wed, 10 Jun 2015 00:10:33 -0400 Subject: [PATCH 16/21] yeah --- sric_script.py~ | 68 ------------------------------------------------- 1 file changed, 68 deletions(-) delete mode 100644 sric_script.py~ diff --git a/sric_script.py~ b/sric_script.py~ deleted file mode 100644 index 569a797..0000000 --- a/sric_script.py~ +++ /dev/null @@ -1,68 +0,0 @@ -import subprocess -from ftplib import FTP # I'd rather use ftputil, since it's a nice wrapper for ftplib, but it might make things slower? -from Modules.file_parse.__file_parse__ import obt_login -from Modules.file_parse.__file_parse__ import obt_pass -from Modules.file_parse.__file_parse__ import obt_message - -# The IP of the server we're downloading/uploading things to/from -ftp_addr = 192.168.1.1 - -# The names of the files were dealing with -download = 'team1.txt' -upload = open('upload_package.txt', 'r') -creds_file = open('credentials.txt', 'wb') - -# Where we want to put the file -upload_name = 'CNU/IMPRINT_upload_package.txt' -team_dir = 'auvsi/team1/' - -# Set up the FTP object -FTP.set_debuglevel(2) - -# Loop forever! -while True: - -# # Verify connection -# # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s -# output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... -# if output = 'tmp string for network down': -# continue - - # We don't need to verify that we have a valid connection, because ftplib will do that for us. - try: - ftp = FTP(ftp_addr, timeout = 1) - except ftplib.all_errors, e: - print "FTP ERROR:", e - continue - - # connect to the FTP object and Login anonymously - ftp = FTP(ftp_addr) - ftp.login() - - # Change directory if needed - if team_dir: - ftp.cwd(team_dir) - - # Need to do more testing with this line, we might be able to just use storelines or retrlines... - ftp.retrbinary('RETR', creds_file.write) - ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) - - # Parse it mytext reads all lines of the file contents - # up_usr and up_pass defined in file contents - text = creds_file.readlines() - - up_user = obt_login(text) - up_pass = obt_pass(text) - up_mess = obt_message(text) - - # Login with the new creds and put the file - ftp.login(up_user, up_pass) - ftp.storelines('STOR', upload_name, upload) - - # End this script to save resources for other things - ftp.quit() - cred_file.close() - uplaod.close() - break - -# Not currently connected... Time to try again From c7d1a9a6fd4f474947c5b381d58a08dba0b885ce Mon Sep 17 00:00:00 2001 From: David Kroell Date: Wed, 10 Jun 2015 00:21:05 -0400 Subject: [PATCH 17/21] updating --- sric_script.py | 2 +- sric_script.py~ | 67 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 sric_script.py~ diff --git a/sric_script.py b/sric_script.py index e59b65d..5384c3f 100644 --- a/sric_script.py +++ b/sric_script.py @@ -5,7 +5,7 @@ from Modules.file_parse.__file_parse__ import obt_message # The IP of the server we're downloading/uploading things to/from -ftp_addr = 192.168.1.1 +ftp_addr = '192.168.1.1' # The names of the files were dealing with download = 'team1.txt' diff --git a/sric_script.py~ b/sric_script.py~ new file mode 100644 index 0000000..e59b65d --- /dev/null +++ b/sric_script.py~ @@ -0,0 +1,67 @@ +import subprocess +from ftplib import FTP # I'd rather use ftputil, since it's a nice wrapper for ftplib, but it might make things slower? +from Modules.file_parse.__file_parse__ import obt_login +from Modules.file_parse.__file_parse__ import obt_pass +from Modules.file_parse.__file_parse__ import obt_message + +# The IP of the server we're downloading/uploading things to/from +ftp_addr = 192.168.1.1 + +# The names of the files were dealing with +download = 'team1.txt' +upload = open('upload_package.txt', 'r') +creds_file = open('credentials.txt', 'wb') + +# Where we want to put the file +upload_name = 'CNU/IMPRINT_upload_package.txt' +team_dir = 'auvsi/team1/' + +# Set up the FTP object +FTP.set_debuglevel(2) + +# Loop forever! +while True: + +# # Verify connection +# # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s +# output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... +# if output = 'tmp string for network down': +# continue + + # We don't need to verify that we have a valid connection, because ftplib will do that for us. + try: + ftp = FTP(ftp_addr, timeout = 1) + except ftplib.all_errors, e: + print "FTP ERROR:", e + continue + + # Connect to the FTP object and Login anonymously + ftp = FTP(ftp_addr) + ftp.login() + + # Change directory if needed + if team_dir: + ftp.cwd(team_dir) + + # Need to do more testing with this line, we might be able to just use storelines or retrlines... +# ftp.retrbinary('RETR', creds_file.write) + ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) + + # Parse it mytext reads all lines of the file contents + text = creds_file.readlines() + + up_user = obt_login(text) + up_pass = obt_pass(text) + up_mess = obt_message(text) + + # Login with the new creds and put the file + ftp.login(up_user, up_pass) + ftp.storelines('STOR', upload_name, upload) + + # End this script to save resources for other things + ftp.quit() + cred_file.close() + upload.close() + break + +# Not currently connected... Time to try again From c679d79ab8da3a84769c1ba9b62edf36cd0b98b7 Mon Sep 17 00:00:00 2001 From: Jake Tarren Date: Sun, 14 Jun 2015 14:01:29 -0400 Subject: [PATCH 18/21] some shitty last minute fixes --- .../{__file_parse__.py => file_parse.py} | 32 ++++----- __init__.py | 0 credentials.txt | 0 file_parse.py | 39 ++++++++++ file_parse.pyc | Bin 0 -> 801 bytes sric_script.py | 6 +- sric_script.py~ | 67 ------------------ 7 files changed, 58 insertions(+), 86 deletions(-) rename Modules/file_parse/{__file_parse__.py => file_parse.py} (67%) create mode 100644 __init__.py create mode 100644 credentials.txt create mode 100644 file_parse.py create mode 100644 file_parse.pyc delete mode 100644 sric_script.py~ diff --git a/Modules/file_parse/__file_parse__.py b/Modules/file_parse/file_parse.py similarity index 67% rename from Modules/file_parse/__file_parse__.py rename to Modules/file_parse/file_parse.py index c68d501..02742be 100644 --- a/Modules/file_parse/__file_parse__.py +++ b/Modules/file_parse/file_parse.py @@ -21,19 +21,19 @@ def obt_message(text): return mess_line -#file concatination: -file = open('testfiles/'+sys.argv[1]) -text = file.readlines() - -#Printing the test file credentials - -usr_login = obt_login(text) -print(usr_login) - -usr_pass = obt_pass(text) -print(usr_pass) - -usr_mess = obt_message(text) -print(usr_mess) - - +##file concatination: +#file = open('testfiles/'+sys.argv[1]) +#text = file.readlines() +# +##Printing the test file credentials +# +#usr_login = obt_login(text) +#print(usr_login) +# +#usr_pass = obt_pass(text) +#print(usr_pass) +# +#usr_mess = obt_message(text) +#print(usr_mess) +# +# diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/credentials.txt b/credentials.txt new file mode 100644 index 0000000..e69de29 diff --git a/file_parse.py b/file_parse.py new file mode 100644 index 0000000..02742be --- /dev/null +++ b/file_parse.py @@ -0,0 +1,39 @@ + +import sys + +#methods for obtaining credentials from a sample file. +#The paramemter passed is the file itself once opened. +#these methods are based on the sample of how the credentials will be sent remotely. + +def obt_login(text): + first_line = text[0] + line_list = first_line.split(',') +#indentation can cause an error + return line_list[0].replace(" ", "") + +def obt_pass(text): + first_line = text[0] + line_list = first_line.split(',') + return line_list[1].replace(" ", "") + +def obt_message(text): + mess_line = text[1] + return mess_line + + +##file concatination: +#file = open('testfiles/'+sys.argv[1]) +#text = file.readlines() +# +##Printing the test file credentials +# +#usr_login = obt_login(text) +#print(usr_login) +# +#usr_pass = obt_pass(text) +#print(usr_pass) +# +#usr_mess = obt_message(text) +#print(usr_mess) +# +# diff --git a/file_parse.pyc b/file_parse.pyc new file mode 100644 index 0000000000000000000000000000000000000000..58417557c92b08c0fbfe6b484d61c777f42a4f05 GIT binary patch literal 801 zcmbV}&rZTX5XN^~K#Ttlp12uLP5jdrFviHq3x_3MypT#4T(Z!HSrSR$gfHeZ`2afK zl!SN_o9^`6X6M`a&BR|P?c{U)JXG5!;_m}5y5dmqtCd&kg+-)3SZGzmA|h2ZM8r7L zPn&$+ee=^BYL@YKb@@v-99H7hS!=b@Y9f9ct=5rRv6EJvi8!<8Cfd679H*%Ow`++P z0Y6fd7;qg`-i2_$YHll^4{eHDLj%FShtOs*a&rm;?`Ae6yoKN$g_Ji+0$sAo-pZ-X zDwjPjoG&Qro2PCza^4QAd`|YZT1tBP%3kHz%?>$-TJX?qeHQ%#Ij)f#s%X~8aI29G zd>y!r1ON-Q0iOY%kQy|>AkUx)`y+t@NL5aB%6dnng$Ng8$q;ei*AV+sQ%?%5@5Wgv zN}4sbMAG^F3p-*X6b6fYY|nX1z(%)InJ+p)OEN$(n5;q0?j})x9W6}mre(44_8tt< KhvQb#N}4}3A&YeY literal 0 HcmV?d00001 diff --git a/sric_script.py b/sric_script.py index 5384c3f..d48472e 100644 --- a/sric_script.py +++ b/sric_script.py @@ -1,8 +1,8 @@ import subprocess from ftplib import FTP # I'd rather use ftputil, since it's a nice wrapper for ftplib, but it might make things slower? -from Modules.file_parse.__file_parse__ import obt_login -from Modules.file_parse.__file_parse__ import obt_pass -from Modules.file_parse.__file_parse__ import obt_message +from file_parse import obt_login +from file_parse import obt_pass +from file_parse import obt_message # The IP of the server we're downloading/uploading things to/from ftp_addr = '192.168.1.1' diff --git a/sric_script.py~ b/sric_script.py~ deleted file mode 100644 index e59b65d..0000000 --- a/sric_script.py~ +++ /dev/null @@ -1,67 +0,0 @@ -import subprocess -from ftplib import FTP # I'd rather use ftputil, since it's a nice wrapper for ftplib, but it might make things slower? -from Modules.file_parse.__file_parse__ import obt_login -from Modules.file_parse.__file_parse__ import obt_pass -from Modules.file_parse.__file_parse__ import obt_message - -# The IP of the server we're downloading/uploading things to/from -ftp_addr = 192.168.1.1 - -# The names of the files were dealing with -download = 'team1.txt' -upload = open('upload_package.txt', 'r') -creds_file = open('credentials.txt', 'wb') - -# Where we want to put the file -upload_name = 'CNU/IMPRINT_upload_package.txt' -team_dir = 'auvsi/team1/' - -# Set up the FTP object -FTP.set_debuglevel(2) - -# Loop forever! -while True: - -# # Verify connection -# # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s -# output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... -# if output = 'tmp string for network down': -# continue - - # We don't need to verify that we have a valid connection, because ftplib will do that for us. - try: - ftp = FTP(ftp_addr, timeout = 1) - except ftplib.all_errors, e: - print "FTP ERROR:", e - continue - - # Connect to the FTP object and Login anonymously - ftp = FTP(ftp_addr) - ftp.login() - - # Change directory if needed - if team_dir: - ftp.cwd(team_dir) - - # Need to do more testing with this line, we might be able to just use storelines or retrlines... -# ftp.retrbinary('RETR', creds_file.write) - ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) - - # Parse it mytext reads all lines of the file contents - text = creds_file.readlines() - - up_user = obt_login(text) - up_pass = obt_pass(text) - up_mess = obt_message(text) - - # Login with the new creds and put the file - ftp.login(up_user, up_pass) - ftp.storelines('STOR', upload_name, upload) - - # End this script to save resources for other things - ftp.quit() - cred_file.close() - upload.close() - break - -# Not currently connected... Time to try again From bc57aadf7b8e856c25f0cef53a5aff4e72030b43 Mon Sep 17 00:00:00 2001 From: Jake Tarren Date: Sun, 14 Jun 2015 16:34:07 -0400 Subject: [PATCH 19/21] My hands hurt from chopping Austins wood... --- CNU.txt | 2 ++ credentials.txt | 0 creds.txt | 1 + sric_script.py | 20 ++++++++++---------- 4 files changed, 13 insertions(+), 10 deletions(-) create mode 100644 CNU.txt delete mode 100644 credentials.txt create mode 100644 creds.txt diff --git a/CNU.txt b/CNU.txt new file mode 100644 index 0000000..e75e7ed --- /dev/null +++ b/CNU.txt @@ -0,0 +1,2 @@ +austin:pr0ject.px +This is a triumph diff --git a/credentials.txt b/credentials.txt deleted file mode 100644 index e69de29..0000000 diff --git a/creds.txt b/creds.txt new file mode 100644 index 0000000..419b521 --- /dev/null +++ b/creds.txt @@ -0,0 +1 @@ +This is a triumph diff --git a/sric_script.py b/sric_script.py index d48472e..3e37b4d 100644 --- a/sric_script.py +++ b/sric_script.py @@ -5,7 +5,7 @@ from file_parse import obt_message # The IP of the server we're downloading/uploading things to/from -ftp_addr = '192.168.1.1' +ftp_addr = '192.168.1.200' # The names of the files were dealing with download = 'team1.txt' @@ -22,15 +22,14 @@ # Loop forever! while True: -# # Verify connection -# # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s -# output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... -# if output = 'tmp string for network down': -# continue + # Verify connection before attempting to create FTP instance so we don't have to wait for 30 second timeout + # Does ftplib automatically check connections? If so we should remove this whole block and set ftplib's timeout to like, 1s + output = subprocess.check_output(['ping', '-n', '1', server]) # Need to fix this command to work on linux.... + if output = 'tmp string for network down': + continue - # We don't need to verify that we have a valid connection, because ftplib will do that for us. try: - ftp = FTP(ftp_addr, timeout = 1) + ftp = FTP(ftp_addr, timeout = 30) except ftplib.all_errors, e: print "FTP ERROR:", e continue @@ -45,7 +44,7 @@ # Need to do more testing with this line, we might be able to just use storelines or retrlines... # ftp.retrbinary('RETR', creds_file.write) - ftp.retrlines("RETR " + download, lambda s, w = creds_file.write: w(s + "\n")) + ftp.retrlines('RETR ' + download, lambda s, w = creds_file.write: w(s + '\n')) # Parse it mytext reads all lines of the file contents text = creds_file.readlines() @@ -55,7 +54,8 @@ up_mess = obt_message(text) # Login with the new creds and put the file - ftp.login(up_user, up_pass) + ftp.quit() + ftp = FTP(ftp_addr, up_user, up_pass, timeout = 30) ftp.storelines('STOR', upload_name, upload) # End this script to save resources for other things From 0f14432f0250d0d4a3176b83416b11a53cd4b5ca Mon Sep 17 00:00:00 2001 From: Jake Tarren Date: Sun, 14 Jun 2015 17:01:49 -0400 Subject: [PATCH 20/21] Removes credentials variables --- sric_script.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/sric_script.py b/sric_script.py index 3e37b4d..f6b5c40 100644 --- a/sric_script.py +++ b/sric_script.py @@ -14,7 +14,7 @@ # Where we want to put the file upload_name = 'CNU/IMPRINT_upload_package.txt' -team_dir = 'auvsi/team1/' +team_dir = '/home/austin' # Set up the FTP object FTP.set_debuglevel(2) @@ -48,14 +48,10 @@ # Parse it mytext reads all lines of the file contents text = creds_file.readlines() - - up_user = obt_login(text) - up_pass = obt_pass(text) - up_mess = obt_message(text) # Login with the new creds and put the file ftp.quit() - ftp = FTP(ftp_addr, up_user, up_pass, timeout = 30) + ftp = FTP(ftp_addr, obt_login(text), obt_pass(text), timeout = 30) ftp.storelines('STOR', upload_name, upload) # End this script to save resources for other things From 6c00a3a2094b91d6879f1c0da4da29f52b55eb87 Mon Sep 17 00:00:00 2001 From: Jake Tarren Date: Sun, 14 Jun 2015 17:20:26 -0400 Subject: [PATCH 21/21] Fixes part of uploading --- sric_script.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sric_script.py b/sric_script.py index f6b5c40..f86330c 100644 --- a/sric_script.py +++ b/sric_script.py @@ -52,7 +52,7 @@ # Login with the new creds and put the file ftp.quit() ftp = FTP(ftp_addr, obt_login(text), obt_pass(text), timeout = 30) - ftp.storelines('STOR', upload_name, upload) + ftp.storlines('STOR ', upload_name, upload) # End this script to save resources for other things ftp.quit()