首页 / 时尚家居 / 正文

文件路径出错文件不存在常常出现no such file如何解决

来源:
编辑:亿尚风范
时间:2023-10-17

    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 @ 2005-2024 Reserved 亿尚网版权所有,所涉内容请查询声明细则