从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. 自学Python5.2-类和对象概念

    自学Python之路 自学Python5.2-类和对象概念 面向对象编程的2个非常重要的概念:类和对象 对象是面向对象编程的核心: 在使用对象的过程中,为了将具有共同特征和行为的一组对象抽象定义,提出 ...

  2. 【BZOJ2281】[SDOI2011]黑白棋(博弈论,动态规划)

    [BZOJ2281][SDOI2011]黑白棋(博弈论,动态规划) 题面 BZOJ 洛谷 题解 先看懂这题目在干什么. 首先BZOJ上面的题面没有图,换到洛谷看题就有图了. 不难发现都相邻的两个异色棋 ...

  3. BZOJ3730 震波 | 动态点分治

    #include <cstdio> #include <cstring> #include <cmath> #include <algorithm> # ...

  4. source、sh、bash

    source.sh.bash../ 执行脚本的区别 1.source命令用法: source FileName 作用:在当前bash环境下读取并执行FileName中的命令.该filename文件可以 ...

  5. 在Sqlite中通过Replace来实现插入和更新

      你可能在批量处理一个事务的时候,想要批量插入一系列的数据,但是这些数据当添加完一次之后,重新添加的时候,你不想要重新添加,只是想将原有的数据进行更新,例如:我想要通过Excel将一系列的图书导入到 ...

  6. vs widows服务的发布

    1.在service1.cs里空白处点击右键,弹出菜单选择 添加安装程序 2.自动生成ProjectInstaller.cs文件后 可在InitializeComponent()方法里自定义服务名称 ...

  7. 无法使用备份文件 'D:\20160512.bak',因为原先格式化该文件时所用扇区大小为 512,而目前所在设备的扇区大小为 4096

    删除原先备份的记录 这里再加一条,如果你备份的文件还原有兼容性的问题,那就用低版本的sql做备份,这样的话哪里都能用

  8. .Net MVC个人笔记

    关于转向的问题,目前知道的是Response.Redirect 和 location.href 我现在有两个controller,Home和Test <h2>this is Home< ...

  9. UVA - 12487 Midnight Cowboy(LCA+思维)

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  10. UVA 10382 Watering Grass(区间覆盖)

    n sprinklers are installed in a horizontal strip of grass l meters long and w meters wide. Each spri ...