windows上python上传下载文件到linux服务器指定路径【转】
从windows上传文件到linux,目录下的文件夹自动创建
#!/usr/bin/env python
# coding: utf-8
import paramiko
import datetime
import os hostname='10.xxx.xxx.xx'
username='username'
password='***'
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('[%s][%s][%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('',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'D:\111'
remote_dir='/home/share/111/'
upload(local_dir,remote_dir)
windows上用python从linux服务器下载文件到指定路径
#!/usr/bin/env python
# coding: utf-8
import paramiko
def remote_scp(host_ip,remote_path,local_path,username,password):
t = paramiko.Transport((host_ip,22))
t.connect(username=username, password=password)
sftp = paramiko.SFTPClient.from_transport(t)
src = remote_path
des = local_path
sftp.get(src,des)
t.close() if __name__ == '__main__':
host_ip = '10.xxx.xxx.xx'
remote_path = '/home/share/a.pdf'
local_path = r'D:\aaa\a.pdf1'
username = 'username'
password = '******'
remote_scp(host_ip,remote_path,local_path,username,password)
转自
windows上python上传文件到linux服务器指定路径 - CSDN博客
https://blog.csdn.net/weixin_40539892/article/details/79097386
windows上python上传下载文件到linux服务器指定路径【转】的更多相关文章
- 上传下载文件到Linux服务器
转自链接:https://blog.csdn.net/drdongshiye/article/details/89430535Mac的终端是十分强大 , 可以通过命令进行上传下载下载文件夹 scp - ...
- SecureCRT 上传/下载文件到Linux服务器
1. 安装上传/.下载软件 a) cd /tmp wget http://www.ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz tar zxvf lrzsz-0. ...
- linux学习笔记-linux主机上传下载文件至linux虚拟机的方法
我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 1.上传文件 scp -r file 用户名@ip地址:目标目录 2.下载文件 scp -r 用户名@ip地址:文件 目标目录
- 不使用xftp上传/下载文件到linux
yum install lrzsz # 安装软件 window端上传到linux端: 1. window端先压缩需上传的文件 2. linux端运行命令rz 3. 在弹出的窗口选择压缩好的文件, ...
- linux利用sh脚本上传下载文件到ftp服务器
####本地的/app/awsm/csv2 to ftp服务器上的/awsm/#### #!/bin/sh export today=`date +%Y-%m-%d` ftp -v -n 10.116 ...
- windows环境通过cmd命令到ftp上下载文件到linux服务器
转自:http://jingyan.baidu.com/article/6525d4b1300912ac7d2e941b.html
- 用java 代码下载Samba服务器上的文件到本地目录以及上传本地文件到Samba服务器
引入: 在我们昨天架设好了Samba服务器上并且创建了一个 Samba 账户后,我们就迫不及待的想用JAVA去操作Samba服务器了,我们找到了一个框架叫 jcifs,可以高效的完成我们工作. 实践: ...
- Linux上传下载文件快捷命令
远程链接Linux(如SecrueCRT),要上传文件很下载文件到Linux服务器,只需要使用sz或者rz命令即可快速下载和上传文件了. 使用方法: 1.首先确保Linux服务器系统中安装了lrzsz ...
- Linux下不借助工具实现远程linux服务器上传下载文件
# Linux下不借助工具实现远程linux服务器上传下载文件 ## 简介 - Linux下自带ssh工具,可以实现远程Linux服务器的功能- Linux下自带scp工具,可以实现文件传输功能 ## ...
随机推荐
- C#/.NET转Java学习笔记
大学研究了三年的.Net,由于偶然的机会,拿到IBM的Java web实习offer,所以决定转行搞Java(综合了校招情况.发展前景和其他各种因素). 下面是我在学习Java web的一些学习笔记( ...
- 省选前的CF题
RT,即将退役的人懒得一篇篇写题解,于是有了这个东西 CF1004E 树上选一条不超过k个点的链,最小化其余点到链上点的最大距离 这个思路很有意思,不像平时一般的树上问题,是从叶子开始一点点贪心合并直 ...
- 在 CentOS 6.x 上安装最新版本的 git
在 CentOS 的默认仓库中有git,所以最简单的方法是: $ sudo yum install git 这种方法虽然简单,但是一般仓库里的版本更新不及时,比如 CentOS 仓库中的 git 最新 ...
- 线程的中断.interrupt
线程对象.interrupt() 注意,异常分析中要有break,否则无法中断 public class Demo extends JFrame { private Thread thread;//定 ...
- Prometheus Redis_exporter
Redis 下载redis_exporter wget https://github.com/oliver006/redis_exporter/releases/download/v0.15.0/re ...
- list 删除一个元素的三种做法--python
我们以一个字符串为元素类型的 list 为例,进行列表元素的删除: l = ['no surfing', 'flippers'] 法一:remove(val) >>> l.remov ...
- CentOS下的yum upgrade和yum update区别
说明:生产环境对软件版本和内核版本要求非常精确,别没事有事随便的进行yum update操作!! ! yum update:升级所有包同时也升级软件和系统内核 yum upgrade:只升级所有包,不 ...
- ruby pluck用法,可以快速从数据库获取 对象的 指定字段的集合数组
可以快速从数据库获取 对象的 指定字段的集合数组 比如有一个users表,要等到user的id数组: select id from users where age > 20; 要实现在如上sql ...
- 【1】【JUC】JDK1.8源码分析之ArrayBlockingQueue,LinkedBlockingQueue
概要: ArrayBlockingQueue的内部是通过一个可重入锁ReentrantLock和两个Condition条件对象来实现阻塞 注意这两个Condition即ReentrantLock的Co ...
- Networx蓝屏问题
本人系统win7专业版64位. 从5月底开始就时不时有蓝屏发生,而且可以说是没有任何征兆就"啪"的一下蓝了... 有时候是隔个四五天蓝屏一次,有时候一天都能蓝好几次,实在是让人恼火 ...