FTP:IOError:[Errno 22]无效模式('rb')或文件名

时间:2015-09-02 14:14:12

标签: python ftp

我正在尝试在FTP服务器中搜索特定关键字的.gz文件列表。问题是,当我使用gzip.open函数时,我收到以下错误:

with gzip.open(fullpath,'rb') as content: 
File "C:\Pytho27\lib\gzip.py", line 34, in open 
   return GzipFile(filename,mode, compresslevel)  
File "C:\Python27\lib\gzip.py", line 94, in __init__ 
   fileobj = self.myfileobj = __builtin__.open(filename,mode or 'rb') 
IOError: [Errrno 22] invalid mode ('rb') or filename '/E:/FTP/ROKO/TEST\\PDT.TSR.LL.MAP.gz' 

实际上我们似乎弄乱了FTP路径并且无法找到该文件!

下面你可能会看到我的剧本:

import sys
import os 
import gzip
import ftplib 
from os import path  
from Tkinter import *
import tkSimpleDialog
import tkMessageBox

#### This program opens a connection to a FTP server and gets some files 
#######################################################
##Open FTP connection 
ftp = ftplib.FTP('ftp.something.com','username','password') 
##change directory  
ftp.cwd('\E:\FTP\ROKO\TEST')
path=ftp.pwd()
files = []

### set up a GUI for user
root=Tk()
w = Label(root, text="Search Tool")
w.pack()

variable_string  = tkSimpleDialog.askstring("Alpha Numeric Search","Please enter a string  value:")
try:
    files = ftp.nlst()

except ftplib.error_perm, resp:
    if str(resp) == "550 No files found":
        print "No files in this directory"
    else:
        raise
count=0
for f in files:
## reads the content of each file
    fullpath =os.path.join(path,f)
    print fullpath
    base_name=os.path.basename(f)
    print base_name
    with gzip.open(fullpath,'rb') as content:
        file_content=content.read()
        print file_content
        base_name=os.path.basename(f)
        for line in file_content:
            if str(variable_integer) in line:
                print line,base_name   
            else:
                print "not available"
    count=count+1
print count  

0 个答案:

没有答案
相关问题