0

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
glibdud
  • 7,550
  • 4
  • 27
  • 37
krock1516
  • 441
  • 10
  • 30

1 Answers1

2

#!/usr/bin/python env should be #!/usr/bin/env python

except ftplib.error_perm, resp This synthax is not supported in python3. Replace comma with as.

gonczor
  • 3,994
  • 1
  • 21
  • 46