zoukankan      html  css  js  c++  java
  • Python实现Windows和Linux之间互相传输文件(文件夹)的方法

      

    项目中需要从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:STAFlibpythonSBSesxtestpscp.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:STAFlibpythonSBSesxtestpscp.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:STAFlibpythonSBSesxtestpscp.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:STAFlibpythonSBSesxtestpscp.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) 
     
    以上这篇Python实现Windows和Linux之间互相传输文件(文件夹)的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持脚本之家。
     
    来源:https://www.jb51.net/article/113165.htm
  • 相关阅读:
    LeetCode Count of Range Sum
    LeetCode 158. Read N Characters Given Read4 II
    LeetCode 157. Read N Characters Given Read4
    LeetCode 317. Shortest Distance from All Buildings
    LeetCode Smallest Rectangle Enclosing Black Pixels
    LeetCode 315. Count of Smaller Numbers After Self
    LeetCode 332. Reconstruct Itinerary
    LeetCode 310. Minimum Height Trees
    LeetCode 163. Missing Ranges
    LeetCode Verify Preorder Serialization of a Binary Tree
  • 原文地址:https://www.cnblogs.com/sunmoon1993/p/9999369.html
Copyright © 2011-2022 走看看