I'm testing a FTP script in Python 3 to list the files in a directory path give, but when I'm trying with try
/except
handlers, I'm getting a syntax error.
Below is the script code. Please advise what I'm missing or doing wrong.
#!/usr/bin/python env
import ftplib
def FtpMirroList():
ftp = ftplib.FTP("ftp.example.com")
ftp.login("lodgy", "pass123")
ftp.cwd("/my/research/folder")
files = []
try:
files = ftp.nlst()
except ftplib.error_perm, resp:
if str(resp) == "550 No files found":
printi("No files in this directory")
else:
raise
for f in files:
printi(f)
FtpMirroList()
It's raising the below error:
File "./ftplib-example-2.py", line 12
except ftplib.error_perm, resp:
^
SyntaxError: invalid syntax