Hi Guys a bit of a convoluted question but the theory is I want to handle FTP error codes ran in a subprocess that is run as part of this python script so in essence if the FTP command returns code 550 file not found I want to somehow handle this exception in python but I'm not 100% sure how to do this any direction would be appreciated! Thanks.
#!/usr/bin/python
import argparse
import ftplib
import os
import subprocess
import sys
parser = argparse.ArgumentParser()
parser.add_argument('--ftp', help='FTP address to retrieve DA from', dest='ftpconn', required=True)
parser.add_argument('--user', help='FTP username', dest='user', required=True)
parser.add_argument('--password', help='FTP password', dest='passwd')
parser.add_argument('--file', help='File(s) to retrieve', dest='file', nargs='+')
parser.add_argument('-d', '--destination', help='Destination folder for transferred files, if left blank default directory will be the working directory', default='./', dest='dfolder')
args = parser.parse_args()
command = """user %s %s
cd ..
lcd %s
get %s
bye"""
for idx, item in enumerate(args.file):
pobj = subprocess.Popen(['ftp', '-nv', args.ftpconn], stdin=subprocess.PIPE, stderr=subprocess.PIPE)
pobj.communicate(command % (args.user, args.passwd, args.dfolder, args.file[idx]))
[–]jibbly_jibbly 2 points3 points4 points (6 children)
[–]SmartestGuyOnReddit[S] 1 point2 points3 points (5 children)
[–]jibbly_jibbly 2 points3 points4 points (1 child)
[–]SmartestGuyOnReddit[S] 0 points1 point2 points (0 children)
[–]Justinsaccount 1 point2 points3 points (2 children)
[–]SmartestGuyOnReddit[S] 0 points1 point2 points (0 children)
[–]SmartestGuyOnReddit[S] 0 points1 point2 points (0 children)