首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >处理DMZ时的

处理DMZ时的
EN

Stack Overflow用户
提问于 2015-02-25 13:27:55
回答 1查看 247关注 0票数 0

我创建了一个python脚本,将文件从源文件夹复制到目标文件夹,脚本在本地机器上运行良好。

但是,当我试图将源更改为安装在DMZ中的服务器中的路径,将目标更改为本地服务器中的文件夹时,我得到了以下错误:

代码语言:javascript
复制
FileNotFoundError: [WinError 3] The system cannot find the path specified: '\reports'

下面是剧本:

代码语言:javascript
复制
import sys, os, shutil
import glob
import os.path, time

fob= open(r"C:\Log.txt","a")
dir_src = r"\reports"
dir_dst = r"C:\Dest"
dir_bkp = r"C:\Bkp"

for w in list(set(os.listdir(dir_src)) - set(os.listdir(dir_bkp))):
    if w.endswith('.nessus'):
        pathname = os.path.join(dir_src, w)
        Date_File="%s" %time.ctime(os.path.getmtime(pathname))
        print (Date_File)
        if os.path.isfile(pathname):
                        shutil.copy2(pathname, dir_dst)
                        shutil.copy2(pathname, dir_bkp)
                        fob.write("File Name:   %s" % os.path.basename(pathname))
                        fob.write("   Last modified Date:   %s" % time.ctime(os.path.getmtime(pathname)))
                        fob.write("   Copied On:   %s" % time.strftime("%c"))
                        fob.write("\n")

fob.close()
os.system("PAUSE")
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-02-25 13:43:19

好的,我们首先要看看你有什么样的远程文件夹。

  1. 如果您的远程文件夹是共享的windows网络文件夹,请尝试将其映射为网络驱动器:http://windows.microsoft.com/en-us/windows/create-shortcut-map-network-drive#1TC=windows-7,然后只需使用Z:\reports之类的内容来访问您的文件。
  2. 如果您的远程文件夹实际上是unix服务器,则可以使用paramiko访问它并从它复制文件:

代码语言:javascript
复制
import paramiko, sys, os, posixpath, re

def copyFilesFromServer(server, user, password, remotedir, localdir, filenameRegex = '*', autoTrust=True):
    # Setup ssh connection for checking directory
    sshClient = paramiko.SSHClient()
    if autoTrust:
        sshClient.set_missing_host_key_policy(paramiko.AutoAddPolicy()) #No trust issues! (yes this could potentially be abused by someone malicious with access to the internal network)
    sshClient.connect(server,user,password)
    # Setup sftp connection for copying files
    t = paramiko.Transport((server, 22))
    t.connect(user, password)
    sftpClient = paramiko.SFTPClient.from_transport(t)
    fileList = executeCommand(sshclient,'cd {0}; ls | grep {1}'.format(remotedir, filenameRegex)).split('\n')
    #TODO: filter out empties!
    for filename in fileList:
        try:
            sftpClient.get(posixpath.join(remotedir, filename), os.path.join(localdir, filename), callback=None) #callback for showing number of bytes transferred so far
        except IOError as e:
            print 'Failed to download file <{0}> from <{1}> to <{2}>'.format(filename, remotedir, localdir)





If your remote folder is something served with the webdav protocol, I'm just as interested in an answer as you are.
If your remote folder is something else still, please explain. I have not yet found a solution that treats all equally, but I'm very interested in one.
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28720250

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档