推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
fengxueshangu
V2EX  ›  Python

我又来求助了,想定时把 windows 指定目录下面的文件拷贝到 Linux 上面怎么实现呢?

  •  
  •   fengxueshangu · Jan 17, 2018 · 6920 views
    This topic created in 3213 days ago, the information mentioned may be changed or developed.

    渣渣测试一枚,现在想写一个 python 小脚本,就是定时把一个 win7 上面一个固定目录下的文件拷贝到 linux 上,脚本运行在这个 linux 上面,想了几个库,貌似都不好实现阿,主要是 win7 上面没开启什么服务,有没有简便一点的方法,多谢各位大神指点了。

    Supplement 1  ·  Jan 19, 2018
    一天没有来看,这么多的留言,非常感谢大家,提出了这么多的建议。
    昨天我试了好几种方法,都失败了,原因是公司的安保政策,导致 windows 上面不能安装很多可以开启 ssh 的软件,而且共享文件夹都被安保软件禁止了。至于为什么一定要运行在 linux 上面,而不是 windows 主动上传,是因为这个脚本是作为我们一个运行在 linux 上面的小系统的一部分,所以首先要看看能不能从 linux 上主动去取这个文件,而不是 windows 主动去上传。
    再次感谢大家的回复,我在想一想其他的办法。
    31 replies  •  2018-01-18 13:01:16 +08:00
    yangzhezjgs
    yangzhezjgs
    Jan 17, 2018
    1
    虚拟机?
    WO31400
    WO31400
    Jan 17, 2018
    2
    生成 exe,运行
    anjingme
    anjingme
    Jan 17, 2018
    3
    linux 搞个 samba、nfs 服务,共享给 win7 挂载上,然后定时任务( seccopy 这类软件)把 win7 上文件拷贝到这个挂载目录上
    annielong
    annielong
    Jan 17, 2018
    4
    先 smb 共享?
    geelaw
    geelaw
    Jan 17, 2018
    5
    Windows 上用 Task Scheduler 就可以把文件复制出去啦
    dushixiang
    dushixiang
    Jan 17, 2018
    6
    只需要程序跑在 win7 上就好了,ftp 往 linux 上传。
    h4lbhg1G
    h4lbhg1G
    Jan 17, 2018
    7
    好吧,我再来推广我的 CommandTrayHost

    CommandTrayHost 有一个 crontab 功能,可以精确到秒。然后如果装一个 cygwin,那么你可以用 scp 来传文件。

    写一个 bat 防如下内容

    @ echo off
    C:\cygwin64\bin\bash --login -c "cd ~/work; ./upload.sh"

    然后写一个 update.sh 内容如下

    #!/bin/bash

    rsync -rltcv --no-perms --progress --compress -e ssh nginx/nginx.conf nginx/sites-available nginx/snippets [email protected]:/etc/nginx/
    h4lbhg1G
    h4lbhg1G
    Jan 17, 2018
    8
    然后加一个 CommandTrayHost 的配置如下

    {
    "name": "自动上传",
    "path": "C:\\Windows\\System32",
    "cmd": "cmd.exe upload.bat",
    "working_directory": "D:\\bat_script",
    "addition_env_path": "",
    "use_builtin_console": false,
    "is_gui": false,
    "enabled": false,
    // 可选
    "start_show": false,
    "crontab_config": { // crontab 配置
    "crontab": "5 */6 * * * *", // 每 6 分钟上传一次
    "method": "restart", // 支持的有 start restart stop
    "count": 0, // 0 表示不只限制,大于 0 的整数,表示运行多少次就不运行了
    },
    },
    vibbow
    vibbow
    Jan 17, 2018
    9
    非轮子的话,就直接用 goodsync
    imn1
    imn1
    Jan 17, 2018
    10
    同步省事多了
    vibbow
    vibbow
    Jan 17, 2018
    11
    或者用 rclond + 计划任务
    imcnan
    imcnan
    Jan 17, 2018
    12
    你如果用的是 vm 虚拟机,可以直接使用目录映射,在 Linux 里直接访问 windows 的对应目录。
    h4lbhg1G
    h4lbhg1G
    Jan 17, 2018
    13
    嗯 上面的有个问题 enabled 要改成 true 才能一打开就自动运行。我发现我好像歪题了,赶紧逃<_
    vibbow
    vibbow
    Jan 17, 2018
    14
    @vibbow #11 更正:rclone
    tushankaka
    tushankaka
    Jan 17, 2018 via Android
    15
    定时 scp 不行么。(我也不知道对不对。。)
    imcnan
    imcnan
    Jan 17, 2018
    16
    如果是两个隔离的机器,你就直接在 win7 上启动一个简单的 httpfileserver 吧,用 python 起一个就行了,或者用别的。
    kemad
    kemad
    Jan 17, 2018
    17
    可以不同步,有条件的话,Windows 开共享,Linux 上 smbmount,搞定。
    Beebird
    Beebird
    Jan 17, 2018
    18
    假定 Windows 和 Linux 在同一子网,我用过两种方法:
    1. Windows 装 sshd 服务(记不清是否依赖 cygwin 了),Linux 定时用 scp 或 rsync
    2. Windows 目录设置共享,Linux 上将该目录用 cifs 挂载到本地。

    根据经验,第二种更可靠,不依赖额外的服务。
    songz
    songz
    Jan 17, 2018 via Android
    19
    两边安个 resilio 搞定
    clino
    clino
    Jan 17, 2018
    20
    syncthing
    dl2k
    dl2k
    Jan 17, 2018
    21
    在 win 的机器上跑个定时任务做 PSCP 就好了
    likuku
    likuku
    Jan 17, 2018
    22
    windows 计划任务 定时跑 rsync 把指定目录 推到 linux 服务器。

    不同子网 /公网? openvpn 把 win 和 linux 连起来。

    十几年前就是这么玩的,简单可靠。
    likuku
    likuku
    Jan 17, 2018
    23
    cwRsync - Rsync for Windows | itefix.net : https://www.itefix.net/cwrsync
    20has
    20has
    Jan 17, 2018 via Android
    24
    rsync+cwrsync 还是增量备份 哈哈哈哈 楼上的和我说的一样
    catror
    catror
    Jan 17, 2018 via Android
    25
    单向同步,跑个定时任务就行了
    N0stalgia
    N0stalgia
    Jan 17, 2018
    26
    samba 或者 U 盘,lol
    mkeith
    mkeith
    Jan 17, 2018
    27
    winscp
    killeder
    killeder
    Jan 17, 2018 via Android
    28
    git?
    skyrem
    skyrem
    Jan 17, 2018
    29
    @Beebird #18 恰好知道一个不依赖 cygwin 的 sshd
    http://www.powershellserver.com/
    suspended
    suspended
    Jan 18, 2018
    30
    为什么不从 Win7 上定时运行个 scp 命令,非要从 Linux 上反过来做?
    wizardoz
    wizardoz
    Jan 18, 2018
    31
    计划任务
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   4862 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 96ms · UTC 05:52 · PVG 13:52 · LAX 21:52 · JFK 00:52
    ♥ Do have faith in what you're doing.