what error are you referring to when creating a local directory in Python?

1

I create a function to download an FTP Server directory and try to create it before in local and I miss an error

def Down_Dir(ftp, dir):

    ftp.cwd('\datos')
    try:       
        os.makedirs(os.getcwd()+"\"+dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise      

    os.chdir(os.getcwd()+"\"+dir)

This is the error that gives me:

Traceback (most recent call last):
  File "Pruebas_Arrays.py", line 267, in <module>
    conexionFtp(elemento[0],elemento[1],elemento[2],elemento[3],elemento[4],elemento[5],elemento[6], marcaTiempo, elemento[7])
  File "Pruebas_Arrays.py", line 136, in conexionFtp
    ftp.retrbinary('RETR ' + fich, open(rutaLocal + fich, 'wb').write)
  File "C:\Users\becario2adm\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 442, in retrbinary
    with self.transfercmd(cmd, rest) as conn:
  File "C:\Users\becario2adm\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 399, in transfercmd
    return self.ntransfercmd(cmd, rest)[0]
  File "C:\Users\becario2adm\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 365, in ntransfercmd
    resp = self.sendcmd(cmd)
  File "C:\Users\becario2adm\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 273, in sendcmd
    return self.getresp()
  File "C:\Users\becario2adm\AppData\Local\Programs\Python\Python37-32\lib\ftplib.py", line 246, in getresp
    raise error_perm(resp)
ftplib.error_perm: 550
    
asked by antoniop 05.12.2018 в 12:30
source

1 answer

0

I do not know if this will solve your problem but the best thing when working with directories is to use os.path.join This way your program would be:

def Down_Dir(ftp, dir):

    ftp.cwd('\datos')
    try:       
        os.makedirs(os.path.join(os.getcwd(),dir)
    except OSError as e:
        if e.errno != errno.EEXIST:
            raise      

    os.chdir(os.path.join(os.getcwd(),dir))
    
answered by 05.12.2018 / 18:36
source