Python实现Windows和Linux之间互相传输文件(文件夹)的方法
作者:jingxian 时间:2022-10-15 07:08:14
项目中需要从Windows系统传输ISO文件到Linux测试系统,然后再Linux测试系统里安装这个ISO文件。所以就需要实现如何把文件从Windows系统传输到Linux系统中。
在项目中使用了pscp.exe这个工具,只要按照pscp.exe的使用说明操作即可。只要进入pscp.exe的安装位置,然后输入pscp即可查看pscp的使用说明。
下面是我机器上的:
使用Python实现也挺简单的,下面的code主要介绍4中情况:
1. windows传输文件到Linux
2. windows传输文件夹到Linux
3. Linux传输文件到windows
4. Linux传输文件夹到windows
code如下:(运行环境:python27+eclipse+pydev)
import os
def Window_to_Linux_File(window_path, Linux_path, Linux_ip, username, password):
print '>>>>>>>>>>>>>>>>>>>>>>>>>Window_to_Linux_File begin'
cmd='C:\STAF\lib\python\SBS\esxtest\pscp.exe -pw {password} {window_path} {username}@{Linux_ip}:{Linux_path}'.format(
password=password, window_path=window_path, username=username, Linux_ip=Linux_ip, Linux_path=Linux_path)
os.system(cmd)
print '<<<<<<<<<<<<<<<<<<<<<<<<<<Window_to_Linux_File end'
def Window_to_Linux_Dir(window_path, Linux_path, Linux_ip, username, password):
print '>>>>>>>>>>>>>>>>>>>>>>>>>Window_to_Linux_Dir begin'
cmd='C:\STAF\lib\python\SBS\esxtest\pscp.exe -pw {password} -r {window_path} {username}@{Linux_ip}:{Linux_path}'.format(
password=password, window_path=window_path, username=username,Linux_ip=Linux_ip, Linux_path=Linux_path)
os.system(cmd )
print '<<<<<<<<<<<<<<<<<<<<<<<<<<Window_to_Linux_Dir end'
def Linux_to_Window_File(Linux_path, window_path, Linux_ip, username, password):
print '>>>>>>>>>>>>>>>>>>>>>>>>>Linux_to_Window_File begin'
cmd='C:\STAF\lib\python\SBS\esxtest\pscp.exe -pw {password} {username}@{Linux_ip}:{Linux_path} {window_path}'.format(
password=password, username=username,Linux_ip=Linux_ip, Linux_path=Linux_path, window_path=window_path)
os.system(cmd )
print '<<<<<<<<<<<<<<<<<<<<<<<<<<Linux_to_Window_File end'
def Linux_to_Window_Dir(Linux_path, window_path, Linux_ip, username, password):
print '>>>>>>>>>>>>>>>>>>>>>>>>>Linux_to_Window_Dir begin'
cmd='C:\STAF\lib\python\SBS\esxtest\pscp.exe -pw {password} -r {username}@{Linux_ip}:{Linux_path} {window_path}'.format(
password=password, username=username,Linux_ip=Linux_ip, Linux_path=Linux_path, window_path=window_path)
os.system(cmd)
print '<<<<<<<<<<<<<<<<<<<<<<<<<<Linux_to_Window_Dir end'
if __name__ == '__main__':
password='*****'
window_path=r'D:'
username='****'
Linux_ip='10.**.***.***'
Linux_path=r'/var/backup'
Window_to_Linux_File(window_path, Linux_path, Linux_ip, username, password)
#Window_to_Linux_Dir(window_path, Linux_path, Linux_ip, username, password)
#Linux_to_Window_File(Linux_path, window_path, Linux_ip, username, password))
#Linux_to_Window_Dir(Linux_path, window_path, Linux_ip, username, password)
标签:python,文件传输,Windows,Linux
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Python面向对象之类和实例用法分析
2022-09-09 00:02:33
Elasticsearch的删除映射类型操作示例
2022-05-03 09:46:50
Python爬虫实例——scrapy框架爬取拉勾网招聘信息
2023-01-20 19:06:45
![](https://img.aspxhome.com/file/2023/2/131212_0s.png)
Python matplotlib的使用并自定义colormap的方法
2023-02-02 09:41:40
javascript正则表达式模糊匹配IP地址功能示例
2024-06-12 00:28:10
MySQL数据库中修改密码及访问限制设置详解
2009-09-01 14:19:00
ASP+MSSQL2000 数据库被批量注入后的解决方法第1/2页
2011-04-06 10:50:00
MySQL主从复制之半同步semi-sync replication
2024-01-20 09:48:16
![](https://img.aspxhome.com/file/2023/8/97568_0s.png)
详解使用Pytorch Geometric实现GraphSAGE模型
2021-09-30 21:30:18
开发保留标准的浏览器功能的AJAX应用
2008-02-03 14:03:00
怎么用FSO生成一个UNICODE格式的文本文件
2009-05-26 15:40:00
Python 如何实现数据库表结构同步
2024-01-21 16:38:44
PHP实现断点续传乱序合并文件的方法
2023-06-20 02:35:21
谈一谈基于python的面向对象编程基础
2021-09-09 11:04:39
![](https://img.aspxhome.com/file/2023/3/63543_0s.png)
python爬虫 urllib模块反爬虫机制UA详解
2022-04-07 02:22:51
![](https://img.aspxhome.com/file/2023/9/70209_0s.png)
vue基于websocket实现智能聊天及吸附动画效果
2024-04-30 08:45:20
![](https://img.aspxhome.com/file/2023/1/132991_0s.gif)
python openvc 裁剪、剪切图片 提取图片的行和列
2022-07-03 15:29:40
![](https://img.aspxhome.com/file/2023/4/77874_0s.jpg)
Python读大数据txt
2021-12-29 20:34:12
举例详解Python中smtplib模块处理电子邮件的使用
2023-10-08 04:46:14
Python+unittest+requests 接口自动化测试框架搭建教程
2023-03-27 00:52:07
![](https://img.aspxhome.com/file/2023/1/65121_0s.png)