定制mosspy软件包是否正确?

时间:2018-08-07 12:07:42

标签: python moss broken-pipe

我无法将代码传输到mosspy服务器。

我没有提交文件夹,提交内容在数据库中。

所以,我在下面自定义了一些代码,然后它们返回了断管错误!

出什么问题了?

这是mosspy https://github.com/soachishti/moss.py

的存储库

这是我的通用代码!

file_path获取字符串类型代码,通配符具有字符串类型代码列表

自定义代码的主体

def addBaseFile(self,file_path,display_name = None):
    try:
        self.base_files.append((file_path.encode(),display_name))
    except Exception as e:
        print(e)

def addFile(self,file_path,display_name = None):
    try:
        self.files.append((file_path[0].encode() , display_name))

    except Exception as e:
        print(e)

def addFilesByWildcard(self, wildcard):

    for file in wildcard:
        self.files.append((self.remove_quotes(file[0]).encode(),None))

自定义代码的底部

def uploadFile(self, s, file_path, display_name,file_id):
    if display_name is None:
        display_name = str(random.randint(0,9999999999))

    size = sys.getsizeof(file_path.decode())
    message = "file {0} {1} {2} {3}\n".format(
        file_id,
        self.options['l'],
        size,
        display_name,
    )
    try:
        s.send(message.encode())
        content = file_path
        s.send(content)
    except Exception as e:
        print("ERROR EXECUTED LINE 117", e)
    # content = open(file_path, "rb").read(size)


def send(self):
    s = socket.socket()
    s.connect((self.server, self.port))

    s.send("moss {}\n".format(self.user_id).encode())
    s.send("directory {}\n".format(self.options['d']).encode())
    s.send("X {}\n".format(self.options['x']).encode())
    s.send("maxmatches {}\n".format(self.options['m']).encode())
    s.send("show {}\n".format(self.options['n']).encode())

    s.send("language {}\n".format(self.options['l']).encode())
    recv = s.recv(1024)
    if recv == "no":
        s.send(b"end\n")
        s.close()
        raise Exception("send() => Language not accepted by server")
    #
    # for file_path, display_name in self.base_content:
    try:
        for file_path,display_name in self.base_files:
            self.uploadFile(s, file_path, display_name, 0)
    except Exception as e:
        print("ERROR EXECUTED LINE 145", e)


    try:
        index = 1
        for file_path,display_name in self.files:
            self.uploadFile(s, file_path, display_name, index)
            index += 1
    except Exception as e:
        print("ERROR EXECUTED LINE 155", e)

    s.send("query 0 {}\n".format(self.options['c']).encode())

    response = s.recv(1024)

    s.send(b"end\n")
    s.close()

    return response.decode().replace("\n","")

0 个答案:

没有答案