Transferring Korean directories using Python

Asked 2 years ago, Updated 2 years ago, 69 views

Hello, I'm a beginner at Python. We are working on a program that uses Python to import Korean files connected to FTP. An error occurred when we performed it by squeezing it like below.

import ftplib

import os

ftp = ftplib.FTP()

ftp.connect("113.217.230.27")

ftp.login("","")

ftp.decode='utf-8'

ftp.cwd ("Private Folder")

Error Contents

-------------------------------------------------------------------------------------------------------------------------
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 ("Private Folder")
      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)

I checked with LIST and the Korean alphabet was broken like below I guess you don't recognize the Korean directory sent by cwd Is there any solution? They say that I can set it to utf-8/16 on the Internet, but I can't do it no matter how hard I try Masters, please answer.

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 ÃøÁ¤ µ¥ÀÌÅÍ

anaconda python-3.x

2022-09-20 19:18

1 Answers

ftp.decode='utf-8'

Please revise as below.

ftp.encoding='euc-kr'


2022-09-20 19:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.