Python Forum
upload Files to FTP and file name is Chinese
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
upload Files to FTP and file name is Chinese
#1
hi,

i have a file folder to be uploaded to FTP, but some file names are Simple Chinese, some are traditional Chinese.
Currently,traditional Chinese file names could be uploaded successfully,but Simple Chinese failed.

i define functions as follows
def dirOrflie(name,localpath):
    if os.path.isfile(localpath):
        print("STOR", name, localpath)
        ftp.storbinary('STOR ' + name, open(localpath,'rb'))
    elif os.path.isdir(localpath):
        print("MKD", name)

        try:
            ftp.mkd(name)

        # ignore "directory already exists"
        except error_perm as e:
            if not e.args[0].startswith('550'): 
                raise

            print("CWD", name)
            ftp.cwd(name)
            placeFiles(ftp, localpath)           
            print("CWD", "..")
            ftp.cwd("..")

def placeFiles(ftp, path):
    for name in os.listdir(path):
        print('name='+name)
        localpath = os.path.join(path, name)
        print('localpath='+localpath)
        
        try:
            print('1')
            ftp.encoding='big5'
            print('2')
            dirOrflie(name,localpath)
            print('3')
        except Exception as e:
            print('4')
            ftp.encoding='gbk'
            dirOrflie(name,localpath)
            

try:
    placeFiles(ftp, filenameCV)
    print('successfully')
except Exception as e:
    print('exception'+str(e))
    print('exception bye')
    ftp.quit()          
i tried utf-8, but error message as follows, and traditional Chinese file names also failed
error message:
name=测试档案.xlsx
localpath=C:\Users\User\Desktop\test\测试档案.xlsx
1
2
STOR 测试档案.xlsx C:\Users\User\Desktop\test\测试档案.xlsx
4
STOR 测试档案.xlsx C:\Users\User\Desktop\test\测试档案.xlsx
exception426 Connection closed; file opening failed (ÀɮצWºÙ¡B¥Ø¿ý¦WºÙ©ÎºÏºÐ°Ï¼ÐÅÒ»yªk¿ù»~¡C).
exception bye


i try the code as above, simple Chinese file names are decoded error, for example, local file name is 测试档案.xlsx,but file name uploaded to FTP becomes 聆彸紫偶.xlsx. i tried GBK,GB2312,but have encountered the same problem

Does someone have ideas?
Thanks very much.
Reply
#2
when I try to translate 测试档案.xlsx I get 'Test file .xlsx' with spaces, it that correct?
Reply
#3
The uploaded file name must be the same as the local file name.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Error (Errno 2), File upload with the Flask framework and a public IP Username_Python1 0 123 10 hours ago
Last Post: Username_Python1
  Upload Files to Azure Storage Container phillyfa 6 581 Dec-22-2023, 06:11 AM
Last Post: Pedroski55
  Making a question answering chatbot based on the files I upload into python. Joejones 1 1,151 May-19-2023, 03:09 PM
Last Post: deanhystad
  '' FTP '' File upload with a specified string and rename midomarc 1 1,105 Apr-17-2023, 03:04 AM
Last Post: bowlofred
  how to read chinese character? kucingkembar 2 1,312 Aug-25-2022, 08:42 PM
Last Post: kucingkembar
  Unable to upload file using FTP korenron 2 2,421 Dec-23-2021, 12:44 PM
Last Post: korenron
  How can I upload some files to my website? brunolelli 3 2,234 Mar-17-2021, 01:40 PM
Last Post: snippsat
  Details of attachment files in a msg file such as file names save into a python list klllmmm 2 5,625 Nov-12-2019, 05:59 AM
Last Post: klllmmm
  Upload files to Google/Azure/AWS or cloud drives using python tej7gandhi 0 1,882 May-11-2019, 03:02 PM
Last Post: tej7gandhi
  how to upload a file to my gmail driver after login ?? evilcode1 5 4,099 Nov-06-2018, 07:33 AM
Last Post: evilcode1

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020