从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服务器指定路径【转】的更多相关文章

  1. 上传下载文件到Linux服务器

    转自链接:https://blog.csdn.net/drdongshiye/article/details/89430535Mac的终端是十分强大 , 可以通过命令进行上传下载下载文件夹 scp - ...

  2. SecureCRT 上传/下载文件到Linux服务器

    1. 安装上传/.下载软件 a) cd /tmp wget http://www.ohse.de/uwe/releases/lrzsz-0.12.20.tar.gz tar zxvf lrzsz-0. ...

  3. linux学习笔记-linux主机上传下载文件至linux虚拟机的方法

    我的邮箱地址:zytrenren@163.com欢迎大家交流学习纠错! 1.上传文件 scp -r file 用户名@ip地址:目标目录 2.下载文件 scp -r 用户名@ip地址:文件 目标目录

  4. 不使用xftp上传/下载文件到linux

    yum install lrzsz    # 安装软件 window端上传到linux端: 1. window端先压缩需上传的文件 2. linux端运行命令rz 3. 在弹出的窗口选择压缩好的文件, ...

  5. linux利用sh脚本上传下载文件到ftp服务器

    ####本地的/app/awsm/csv2 to ftp服务器上的/awsm/#### #!/bin/sh export today=`date +%Y-%m-%d` ftp -v -n 10.116 ...

  6. windows环境通过cmd命令到ftp上下载文件到linux服务器

    转自:http://jingyan.baidu.com/article/6525d4b1300912ac7d2e941b.html

  7. 用java 代码下载Samba服务器上的文件到本地目录以及上传本地文件到Samba服务器

    引入: 在我们昨天架设好了Samba服务器上并且创建了一个 Samba 账户后,我们就迫不及待的想用JAVA去操作Samba服务器了,我们找到了一个框架叫 jcifs,可以高效的完成我们工作. 实践: ...

  8. Linux上传下载文件快捷命令

    远程链接Linux(如SecrueCRT),要上传文件很下载文件到Linux服务器,只需要使用sz或者rz命令即可快速下载和上传文件了. 使用方法: 1.首先确保Linux服务器系统中安装了lrzsz ...

  9. Linux下不借助工具实现远程linux服务器上传下载文件

    # Linux下不借助工具实现远程linux服务器上传下载文件 ## 简介 - Linux下自带ssh工具,可以实现远程Linux服务器的功能- Linux下自带scp工具,可以实现文件传输功能 ## ...

随机推荐

  1. selenium 登陆小技巧

    from selenium import webdriver from selenium.webdriver.common.keys import Keys driver = webdriver.Fi ...

  2. 利用docker进行基础镜像制作

    前言 最近想通过Javaee来开发博客,但是不想因为环境配置问题总是耗时间配置相关配置,所以萌生出用docker镜像来搭建web的系统环境,也是作为docker学习实践的笔记. docker hub注 ...

  3. hdu 2577 How to Type(dp)

    Problem Description Pirates have finished developing the typing software. He called Cathy to test hi ...

  4. 支持ajax跨域调用的WCF搭建示例

    支持ajax 跨域调用的WCF搭建 1.新建一个"ASP.NET空Web应用程序"项目. 2.新建一个“WCF服务(支持ajax)”. 3.修改WCFAjaxService.svc ...

  5. ASP.NET MVC 网站优化之压缩技术

    压缩 html 可以去除代码中无用的空格等,这样可提高网站的加载速度并节省带宽. 实现 ActionFilter 来完成 html 的压缩 public class WhitespaceFilterA ...

  6. LVS+keepalived 的DR模式的两种做法

    LVS DR模式搭建 准备工作 三台机器: dr:192.168.13.15 rs1:192.168.13.16 rs2: 192.168.13.17 vip:192.168.13.100 修改DR上 ...

  7. 学习windows编程 day5 之 区域裁剪

    LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) { HDC hdc; PAINTSTRU ...

  8. Hive记录-使用Hue管理Hive元数据

    Hue是一个开源的Apache Hadoop UI系统,由Cloudera Desktop演化而来,最后Cloudera公司将其贡献给Apache基金会的Hadoop社区,它是基于Python Web ...

  9. bzoj千题计划300:bzoj4823: [Cqoi2017]老C的方块

    http://www.lydsy.com/JudgeOnline/problem.php?id=4823 讨厌的形状就是四联通图 且左右各连一个方块 那么破坏所有满足条件的四联通就好了 按上图方式染色 ...

  10. 从匿名函数(闭包特性)到 PHP 设计模式之容器模式

    匿名函数(匿名函数) 匿名函数,也叫闭包函数,它允许临时创建一个没有指定名称的函数,常用作回调函数参数的值,也可以作为变量的值来使用.具体的使用见以下示例代码: /* 示例一:声明一个简单匿名函数,并 ...