sftptransfer.py 文件源码

python
阅读 20 收藏 0 点赞 0 评论 0

项目:core-python 作者: yidao620c 项目源码 文件源码
def transfer_file(hostname_, port_, username_, password_, fdir_, fname_):
    try:
        print('Establishing SSH connection to:', hostname_, port_, '...')
        t = paramiko.Transport((hostname_, port_))
        t.start_client()

        if not t.is_authenticated():
            print('Trying password login...')
            t.auth_password(username=username_, password=password_)

        sftp = paramiko.SFTPClient.from_transport(t)

        local_file = os.path.join(fdir_, fname_)
        remote_file = DIR_REMOTE + '/' + fname_
        try:
            print('start transport...')
            sftp.put(local_file, remote_file)
        except:
            LOG.error('error...')
            raise
        t.close()
        LOG.info('??????????zip??...')
        os.remove(local_file)
    except Exception as e:
        print(e)
        try:
            LOG.info('end transport and close it...')
            t.close()
        except:
            pass
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号