Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从FTP Python获取特殊字符文件名_Python_Ftp - Fatal编程技术网

从FTP Python获取特殊字符文件名

从FTP Python获取特殊字符文件名,python,ftp,Python,Ftp,请支持从FTP下载文件,文件名包含以下特殊字符: def Getting_SPO(): ftp = FTP(ip) ftp.login('nmcman',password) #print "File List:" #files = ftp.dir() directory ="/opt/mv36/core/nmc/hist/raw" #dir i want to download files from, can be changed or left fo

请支持从FTP下载文件,文件名包含以下特殊字符:

def Getting_SPO():

    ftp = FTP(ip)
    ftp.login('nmcman',password)
    #print "File List:" 
    #files = ftp.dir()
    directory ="/opt/mv36/core/nmc/hist/raw" #dir i want to download files from, can be changed or left for user    input
    filematch = "*2018_07_15_2200_NE:15066.CAI2699-TN1_CAI2387-TN1_1.all.cdb*"# a match for any file in this case, can be changed or left for user to input
    ftp.cwd(directory)
    for Spo_file in ftp.nlst(filematch): # Loop - looking for matching files    
        print(ftp.nlst(filematch))
        fhandle = open(Spo_file, 'wb'), sys.Text.Encoding.Unicode
        print( ' \n Getting ' + Spo_file )#for confort sake, shows the file that's being retrieved
        ftp.retrbinary('RETR ' + Spo_file, fhandle.write)

        fhandle.close()
        return Spo_file
filename_MMU2C=Getting_SPO()

解决方法如下:

def Getting_SPO():
  ftp = FTP(ip)
  ftp.login('nmcman',password)
  directory ="/opt/mv36/core/nmc/hist/raw" #dir i want to download files from, can be changed or left for user    input
  filematch = "*NE:12057.HUB0012-5GATH-SPO1_1_1*"# a match for any file in this case, can be changed or left for user to input
  ftp.cwd(directory)
  for Spo_file in ftp.nlst(filematch): # Loop - looking for matching files    
    x =ftp.nlst(filematch)
    x=(x[0].replace(":", "_"), 'wb')
    print(x)

    global fname
    fhandle = open(x[0].replace("all.cdb", "rar"), 'wb')
    fname=x[0].replace("all.cdb", "rar")
    Getting_SPO.fhandle=fhandle
    print( ' \n Getting ' + Spo_file )#for confort sake, shows the file that's being retrieved
    ftp.retrbinary('RETR ' + Spo_file, fhandle.write)
    fhandle.close()
    return Spo_file

什么特别的角色?你是说
?您当前的代码有什么问题?是的,双冒号:好的,所以您实际的问题根本不是FTP,而是写入本地文件。