python 从windows上传文件到linux脚本
import paramiko
import datetime
import os
hostname = '192.168.112.132'
username = 'root'
password = '123456'
port = 22
def upload(local_dir, remote_dir):
try:
t = paramiko.Transport((hostname, port))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
print('upload file start %s ' % datetime.datetime.now())
for root, dirs, files in os.walk(local_dir):
print('[root%s][dirs%s][files%s]' % (root, dirs, files))
for filespath in files:
local_file = os.path.join(root, filespath)
print(11, '[%s][%s][%s][%s]' % (root, filespath, local_file, local_dir))
a = local_file.replace(local_dir, '').replace('\\', '/').lstrip('/')
print('01', a, '[%s]' % remote_dir)
remote_file = os.path.join(remote_dir, a)
print(22, remote_file)
try:
sftp.put(local_file, remote_file)
except Exception as e:
sftp.mkdir(os.path.split(remote_file)[0])
sftp.put(local_file, remote_file)
print("66 upload %s to remote %s" % (local_file, remote_file))
for name in dirs:
local_path = os.path.join(root, name)
print(0, local_path, local_dir)
a = local_path.replace(local_dir, '').replace('\\', '')
print(1, a)
print(1, remote_dir)
remote_path = os.path.join(remote_dir, a)
print(33, remote_path)
try:
sftp.mkdir(remote_path)
print(44, "mkdir path %s" % remote_path)
except Exception as e:
print(55, e)
print('77,upload file success %s ' % datetime.datetime.now())
t.close()
except Exception as e:
print(88, e)
if __name__ == '__main__':
local_dir = r'E:\git_project\git_api_excel'
remote_dir = '/opt/api_excel/' #只支持一级目录
upload(local_dir, remote_dir)
python 从windows上传文件到linux脚本的更多相关文章
- Windows上传文件到linux 使用winscp
Windows上传文件到linux 使用winscp, winscp下载目录 https://sourceforge.net/projects/winscp/postdownload?source=d ...
- windows上传文件到 linux的hdfs
一.windows上传文件到 linux的hdfs 1.先在 centos 上开启 hdfs, 用 jps 可以看到下面信息, 说明完成开启 2.在win上配置 hadoop (https://www ...
- Xshell实现Windows上传文件到Linux主机
我是怎么操作的: 1.打开一台本地Linux虚拟机,使用mount 挂载Windows的共享文件夹到Linux上,然后拷贝数据到Linux虚拟机里面:(经常第一步都不顺利,无法挂载Windows的文件 ...
- linux安装lrzsz支持rz从windows上传文件到linux
1.下载lrzsz wget https://wangxuejin-data-1252194948.cos.ap-shanghai.myqcloud.com/lrzsz-0.12.20.tar.gz ...
- windows 上传文件到 Linux 服务器
方法一: pscp E:\javaWP\new11111.txt username@130.75.7.156:/home/
- windows上传文件到linux
1.在putty的网站上下载putty跟pscp 2.安装ssh跟putty sudo apt-get install openssh-server sudo apt-get install putt ...
- 使用FileZilla解决从Windows上传文件到Linux vsftpd的乱码问题!
日前将golang的开发环境从windows转移到了CentOS6上,为了把以前写得项目代码上传到centos,架设了vsftpd服务,设置为本地用户登录,然后用惯用的ftp软件flashfxp上传了 ...
- 利用Xshell从windows上传文件到linux
1.首先,打开你的xshell客户端. 2.我用的是ubuntu 所以用 apt-get install lrzsz 命令来安装这个上传软件. 安装成功以后,可以使用rz上传,sz下载. 然后等待上传 ...
- windows上传文件到linux云服务器上
安装putty,将pscp.exe移到 C:\Windows\System32 目录下. 在cmd 中执行,pscp -l rot -pw [password] -ls [ip]:/opt 查看目录 ...
随机推荐
- js 禁止重复提交
/*分享按钮*/ var flag = true; $(".recommed a").click(function() { if (flag == true) { getServe ...
- Sql Server 和 Access 数据库在书写sql语句时的语法差异
sql:datediff(d,eff_time,getdate()) access: datediff('d',eff_time,getdate())
- css font简写规则
是不是在很很多网站的公共样式中会看到这样的代码?font: 12px/150% Arial, Verdana, "\5b8b\4f53";意思为:字体大小/行高 字体族 " ...
- 《JavaScript高级程序设计》读书笔记 ---基本概念小结
ECMAScript 中的基本数据类型包括Undefined.Null.Boolean.Number 和String. 与其他语言不同,ECMScript 没有为整数和浮点数值分别定义不同的数据 ...
- gson学习以及进阶文章推荐
Json转换利器Gson之实例一-简单对象转化和带泛型的List转化 (http://blog.csdn.net/lk_blog/article/details/7685169)Json转换利器Gso ...
- kloxo面板教程-折腾了一天
------------------------------------------------------------------------------- 前一晚安装了掉线,不得不重新来,有点慢, ...
- 第九节,基本条件语句if
条件语句 如果我们希望有效的响应用户的输入,代码就需要具有判断能力.能够让程序进行判断的结构成为条件,条件判断语句返回的是布尔值真或假,真就执行一条线路,假就执行另外一条线路 注意if判断如果怎样,否 ...
- hdu_5769_Substring(后缀数组)
题目链接:hdu_5769_Substring 题意: 给你一个字符a和一个串b,问你有多少个包括a的字串 题解: #include<bits/stdc++.h> #define F(i, ...
- 更改Xcode的缺省公司名
更改前: // testAppDelegate.m // test // // Created by gaohf on 11-5-24. // Copyright 2011 __MyCompa ...
- 《Head.First设计模式》的学习笔记(9)--外观模式
意图:为子系统中的一组接口提供一个一致的界面,Facade 模式定义了一个高层接口,这个接口使得这一子系统更加容易使用. 结构: 例子: 假设你有一套杀手级的家庭影院系统,内含DVD播放器.投影仪.自 ...