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工具,可以实现文件传输功能 ## ...
随机推荐
- android 开发中 sdk 无法更新
现在用到android 的多个版本适配 , 换了个新环境 , 重新配置了android 的开发环境,哪想到遇到了很多小问题. 今天又遇到了 android sdk manager 无法更新的问题. ...
- luogu1966 火柴排队(离散化+树状数组)
由于是一个二次函数的关系,所以易证应该尽量让两组的顺序相同 然后就离散化乱搞几发,最后就变成了求逆序对的数量了 #include<bits/stdc++.h> #define pa pai ...
- Gym 100971J-Robots at Warehouse
题目链接:http://codeforces.com/gym/100971/problem/J Vitaly works at the warehouse. The warehouse can be ...
- Java -- JDBC 学习--数据库连接池
JDBC数据库连接池的必要性 在使用开发基于数据库的web程序时,传统的模式基本是按以下步骤: 在主程序(如servlet.beans)中建立数据库连接. 进行sql操作 断开数据库连接. 这种模式开 ...
- A1095. Cars on Campus
Zhejiang University has 6 campuses and a lot of gates. From each gate we can collect the in/out time ...
- 使用 <!DOCTYPE html> 让 <div><img></div>中的图片下面产生几个像素的空白间隔
今天算是第一次使用 <!DOCTYPE html> 不经意间发现图片下方有5个像素左右的空白间隔,检查半天也没查出原因. 最后百度了一下,网上说这是 <!DOCTYPE html&g ...
- win7(旗舰版)下,OleLoadPicture 加载内存中的图片(MagickGetImageBlob),返回值 < 0
昨天去三哥家,想把拍好的照片缩小一下,我用很久前写的一个软件进行缩小,然后进行一次效果预览,这个时候弹出: Call OleLoadPicture Fail - loadPictureFromMW 奇 ...
- c#连接Redis Redis的安装与配置
Redis是一个不错的缓存数据库,读取数据速度效率都很不错.今天大家共同研究下redis的用法.结合网上的资料和自己的摸索,先来看下安装与配置把. 咱们主要看在WINDOWS上怎样使用REDIS数据库 ...
- dojo.js --dojo Quick Start/dojo入门手册1
我看了http://www.cnblogs.com/mylem/archive/2009/11/11/1600984.html这篇博客以后 ,就开始设计自己的代码,其实很多解释都是在我的代码里,所以就 ...
- python - how to sort
python - how to sort overview Key function (★★★★★) OPerator module functions asc and desc 升序和降序 Over ...