头条 科技 产经 家电 智能 手机 芯片 数码 电商 WAP版
中国IT产经新闻网-移动互联网与智能搜索领域是未来IT产业发展的趋势!
中国IT产经新闻/网尚优选/正文
文件路径出错文件不存在常常出现no such file如何解决
来源:
2023-08-18
编辑:晓露

    no such file:没有这样的文件。产生的原因:文件路径出错,文件不存在或者文件名没有加上后缀。问题解决:在我确认我的路径正确后发现,在用ssh协议进行文件传输时,只能将tmp目录下的文件进行传输。所以我将文件转移到tmp下,然后成功了。


      以下是部分代码
      class UpLoad(object):
    private_key_path = 'the path where your private key locates in'
    key = rsakey.RSAKey.from_private_key_file(private_key_path)
    print(key)
    def __init__(self, host='your host IP', port=22, username='your username', key=key):
        self.host = host
        self.port = port
        self.username = username
        self.key = key
        self.__k = None
    def run(self):
        self.connect()
        pass
        self.close()
    def connect(self):
        transport = trans.Transport((self.host, self.port))
        transport.connect(username=self.username,pkey=self.key)
        self.__transport = transport
    def close(self):
        self.__transport.close()
    def upload(self, local_path, target_path):
        # make a connection
        sftp = Sftp.SFTPClient.from_transport(self.__transport)
        # download a file from the server in virtual device
        sftp.put(local_path, target_path)
        print(target_path[5:], "Successfully upload!")
def main():
    ssh = UpLoad()
    ssh.connect()
    ssh.upload('/tmp/filename.py', "/tmp/filename.py")
    ssh.close()
if __name__ == '__main__':
    main()

产业点评更多
厂商动态更多
热门综合更多
CopyRight @ 2008-2024 IT产经新闻网 All Right Reserved 违者必究 湘ICP备2022017330号-2