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 查看目录 ...
随机推荐
- Telnet服务器和域名系统的端口号 Mac OS X
找到Telnet服务器和域名系统的端口号: lapommedeMacBook-Pro:~ lapomme$ grep telnet /etc/services telnet /udp # Telnet ...
- Stash安装和破解
参考资料: http://www.unxmail.com/?p=590 上篇介绍了,Atlassian Stash v2.12.1 破解版的下载, 有同学不会安装. 我重新整理了下文档. 表述我的安装 ...
- java 图形界面 mvc模式控制
使用模型-视图-控件结构来开发GUI程序. 下面的程序演示了MVC模式开发的java程序. 其中CircleModel为模型,包含了圆的半径,是否填充,等属性. CircleView为视图,显示这个圆 ...
- radiobutton以及checkbox背景图片拉伸变形的问题
设置RadioButton的text属性,只需要有这个属性就可以(设置“”内容就行),然后再添加textsize属性,将字体大小属性值设置为比较小,我设置为2sp.运行后我们会发现图片变形问题不复存在 ...
- C语言_愤怒的小鸟
// ConsoleApplication4.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<stdio.h> ...
- nfs服务器的建立
NFS服务器的配置 一.NFS服务器端的配置,即共享发布者 (一)需启动的服务和需安装的软件 1.NFS服务器必须启动两个daemons服务:rpc.nfsd和rpc.mountd rpc.nfs ...
- Educational Codeforces Round 15_D. Road to Post Office
D. Road to Post Office time limit per test 1 second memory limit per test 256 megabytes input standa ...
- CentOS中由一般用户切换为root用户
--->http://www.centoscn.com/CentOS/help/2014/0624/3173.html 1.打开终端,提示符为“$”,表明该用户为普通用户,此时,直接输su,回车 ...
- 在 .NET 4 中使用托管可扩展性框架构建可组合的应用程序
https://msdn.microsoft.com/zh-cn/library/ff576068.aspx http://blogs.msdn.com/b/nblumhardt/archive/20 ...
- .Net配置错误页
1.在web.config中,配置customErrors节,在子节点error中,可以对特定的错误码,进行错误也配置. 配置举例如下: <customErrors mode="Rem ...