편집 기록

편집 기록
  • 프로필 정영훈님의 편집
    날짜2020.12.12

    Python활용 한글 디렉토리 전송하기


    안녕하세요 Python초보입니다. Python활용하여 FTP로 접속 한글 파일을 가져오는 프로그램을 짜고 있습니다. 아래처럼 짜서 수행했더니 Error가 발생하였습니다.

    import ftplib
    
    import os
    
    ftp = ftplib.FTP()
    
    ftp.connect("113.217.230.27")
    
    ftp.login("","")
    
    ftp.decode='utf-8'
    
    ftp.cwd("개인 폴더")
    

    에러 내용

    -------------------------------------------------------------------------------------------------------------------------
    UnicodeEncodeError                        Traceback (most recent call last)
    <ipython-input-63-53e2577e1706> in <module>
          6 ftp.login("skt2","setup2")
          7 ftp.decode='utf-8'
    ----> 8 ftp.cwd("개인 폴더")
          9 ftp.retrlines('LIST')
         10 
    
    ~\Anaconda3\lib\ftplib.py in cwd(self, dirname)
        612             dirname = '.'  # does nothing, but could return error
        613         cmd = 'CWD ' + dirname
    --> 614         return self.voidcmd(cmd)
        615 
        616     def size(self, filename):
    
    ~\Anaconda3\lib\ftplib.py in voidcmd(self, cmd)
        277     def voidcmd(self, cmd):
        278         """Send a command and expect a response beginning with '2'."""
    --> 279         self.putcmd(cmd)
        280         return self.voidresp()
        281 
    
    ~\Anaconda3\lib\ftplib.py in putcmd(self, line)
        199     def putcmd(self, line):
        200         if self.debugging: print('*cmd*', self.sanitize(line))
    --> 201         self.putline(line)
        202 
        203     # Internal: return one line from the server, stripping CRLF.
    
    ~\Anaconda3\lib\ftplib.py in putline(self, line)
        194         if self.debugging > 1:
        195             print('*put*', self.sanitize(line))
    --> 196         self.sock.sendall(line.encode(self.encoding))
        197 
        198     # Internal: send one command to the server (through putline())
    
    UnicodeEncodeError: 'latin-1' codec can't encode characters in position 4-5: ordinal not in range(256)
    

    LIST로 확인해보니 아래처럼 한글이 깨져 나와서 추측하기로 cwd로 보내는 한글 디렉토리를 인식 못하는 것 같은데 해결 방법이 없을까요? 인터넷으로 utf-8/16으로 설정하면 된다고 하는데 아무리 해도 안되서요 고수들 답변 부탁드립니다.

    import ftplib 
    import os
    
    ftp = ftplib.FTP()
    
    ftp.connect("113.217.230.27")
    
    ftp.login("skt2","setup2")
    
    ftp.decode='utf-8'
    
    
    
    ftp.retrlines('LIST')
    
    drwxrwxrwx   1 root     root             4096 Nov 11 18:04 ´Ü¸» ¹ÙÀ̳ʸ®
    
    drwxrwxrwx   1 root     root             4096 Dec  1 11:15 °³ÀÎ Æú´õ
    
    drwxrwxrwx   1 root     root             4096 Oct 30 14:52 SKT ÃøÁ¤ µ¥ÀÌÅÍ
    
    drwxrwxrwx   1 root     root             4096 Nov 11 18:04 PCI ½ºÄ³³Ê µ¥ÀÌÅÍ
    
    drwxrwxrwx   1 root     root             4096 Oct 30 14:54 ONS ÃøÁ¤ µ¥ÀÌÅÍ
    
  • 프로필 nowp님의 편집
    날짜2020.12.11

    Python활용 한글 디렉토리 전송하기


    안녕하세요 Python초보입니다. Python활용하여 FTP로 접속 한글 파일을 가져오는 프로그램을 짜고 있습니다. 아래처럼 짜서 수행했더니 Error가 발생하였습니다.

    import ftplib
    
    import os
    
    ftp = ftplib.FTP()
    
    ftp.connect("113.217.230.27")
    
    ftp.login("skt2","setup2")
    
    ftp.decode='utf-8'
    
    ftp.cwd("개인 폴더")
    

    에러 내용

    -------------------------------------------------------------------------------------------------------------------------
    UnicodeEncodeError                        Traceback (most recent call last)
    <ipython-input-63-53e2577e1706> in <module>
          6 ftp.login("skt2","setup2")
          7 ftp.decode='utf-8'
    ----> 8 ftp.cwd("개인 폴더")
          9 ftp.retrlines('LIST')
         10 
    
    ~\Anaconda3\lib\ftplib.py in cwd(self, dirname)
        612             dirname = '.'  # does nothing, but could return error
        613         cmd = 'CWD ' + dirname
    --> 614         return self.voidcmd(cmd)
        615 
        616     def size(self, filename):
    
    ~\Anaconda3\lib\ftplib.py in voidcmd(self, cmd)
        277     def voidcmd(self, cmd):
        278         """Send a command and expect a response beginning with '2'."""
    --> 279         self.putcmd(cmd)
        280         return self.voidresp()
        281 
    
    ~\Anaconda3\lib\ftplib.py in putcmd(self, line)
        199     def putcmd(self, line):
        200         if self.debugging: print('*cmd*', self.sanitize(line))
    --> 201         self.putline(line)
        202 
        203     # Internal: return one line from the server, stripping CRLF.
    
    ~\Anaconda3\lib\ftplib.py in putline(self, line)
        194         if self.debugging > 1:
        195             print('*put*', self.sanitize(line))
    --> 196         self.sock.sendall(line.encode(self.encoding))
        197 
        198     # Internal: send one command to the server (through putline())
    
    UnicodeEncodeError: 'latin-1' codec can't encode characters in position 4-5: ordinal not in range(256)
    

    LIST로 확인해보니 아래처럼 한글이 깨져 나와서 추측하기로 cwd로 보내는 한글 디렉토리를 인식 못하는 것 같은데 해결 방법이 없을까요? 인터넷으로 utf-8/16으로 설정하면 된다고 하는데 아무리 해도 안되서요 고수들 답변 부탁드립니다.

    import ftplib 
    import os
    
    ftp = ftplib.FTP()
    
    ftp.connect("113.217.230.27")
    
    ftp.login("skt2","setup2")
    
    ftp.decode='utf-8'
    
    
    
    ftp.retrlines('LIST')
    
    drwxrwxrwx   1 root     root             4096 Nov 11 18:04 ´Ü¸» ¹ÙÀ̳ʸ®
    
    drwxrwxrwx   1 root     root             4096 Dec  1 11:15 °³ÀÎ Æú´õ
    
    drwxrwxrwx   1 root     root             4096 Oct 30 14:52 SKT ÃøÁ¤ µ¥ÀÌÅÍ
    
    drwxrwxrwx   1 root     root             4096 Nov 11 18:04 PCI ½ºÄ³³Ê µ¥ÀÌÅÍ
    
    drwxrwxrwx   1 root     root             4096 Oct 30 14:54 ONS ÃøÁ¤ µ¥ÀÌÅÍ
    
  • 프로필 알 수 없는 사용자님의 편집
    날짜2020.12.10

    Python활용 한글 디렉토리 전송하기


    안녕하세요 Python초보입니다. Python활용하여 FTP로 접속 한글 파일을 가져오는 프로그램을 짜고 있습니다. 아래처럼 짜서 수행했더니 Error가 발생하였습니다.

    import ftplib

    import os

    ftp = ftplib.FTP()

    ftp.connect("113.217.230.27")

    ftp.login("skt2","setup2")

    ftp.decode='utf-8'

    ftp.cwd("개인 폴더")

    에러 내용

    UnicodeEncodeError Traceback (most recent call last) in 6 ftp.login("skt2","setup2") 7 ftp.decode='utf-8' ----> 8 ftp.cwd("개인 폴더") 9 ftp.retrlines('LIST') 10

    ~\Anaconda3\lib\ftplib.py in cwd(self, dirname) 612 dirname = '.' # does nothing, but could return error 613 cmd = 'CWD ' + dirname --> 614 return self.voidcmd(cmd) 615 616 def size(self, filename):

    ~\Anaconda3\lib\ftplib.py in voidcmd(self, cmd) 277 def voidcmd(self, cmd): 278 """Send a command and expect a response beginning with '2'.""" --> 279 self.putcmd(cmd) 280 return self.voidresp() 281

    ~\Anaconda3\lib\ftplib.py in putcmd(self, line) 199 def putcmd(self, line): 200 if self.debugging: print('cmd', self.sanitize(line)) --> 201 self.putline(line) 202 203 # Internal: return one line from the server, stripping CRLF.

    ~\Anaconda3\lib\ftplib.py in putline(self, line) 194 if self.debugging > 1: 195 print('put', self.sanitize(line)) --> 196 self.sock.sendall(line.encode(self.encoding)) 197 198 # Internal: send one command to the server (through putline())

    UnicodeEncodeError: 'latin-1' codec can't encode characters in position 4-5: ordinal not in range(256)

    LIST로 확인해보니 아래처럼 한글이 깨져 나와서 추측하기로 cwd로 보내는 한글 디렉토리를 인식 못하는 것 같은데 해결 방법이 없을까요? 인터넷으로 utf-8/16으로 설정하면 된다고 하는데 아무리 해도 안되서요 고수들 답변 부탁드립니다.

    import ftplib import os

    ftp = ftplib.FTP()

    ftp.connect("113.217.230.27")

    ftp.login("skt2","setup2")

    ftp.decode='utf-8'

    ftp.retrlines('LIST')

    drwxrwxrwx 1 root root 4096 Nov 11 18:04 ´Ü¸» ¹ÙÀ̳ʸ®

    drwxrwxrwx 1 root root 4096 Dec 1 11:15 °³ÀÎ Æú´õ

    drwxrwxrwx 1 root root 4096 Oct 30 14:52 SKT ÃøÁ¤ µ¥ÀÌÅÍ

    drwxrwxrwx 1 root root 4096 Nov 11 18:04 PCI ½ºÄ³³Ê µ¥ÀÌÅÍ

    drwxrwxrwx 1 root root 4096 Oct 30 14:54 ONS ÃøÁ¤ µ¥ÀÌÅÍ