简体   繁体   English

复制文件边缘案例

[英]Copy File Edge Case

I have a app running under UserX. 我有一个在UserX下运行的应用程序。 I also have 2 network paths that point to subfolder of the same Share, like: 我也有2个网络路径指向同一Share的子文件夹,例如:

  • P1 = \\\\MyMainShare\\share\\Folder 1 P1 = \\\\MyMainShare\\share\\Folder 1
  • P2 = \\\\MyMainShare\\share\\Folder 2 P2 = \\\\MyMainShare\\share\\Folder 2

UserX has no permission on both P1 and P2 (which means he cant read or write there), but i do have UserP1 and UserP2. UserX在P1和P2上均没有权限(这意味着他无法在此处读写),但是我确实有UserP1和UserP2。 UserP1 can read/write P1 only. UserP1只能读/写P1。 UserP2 can read/write P2 only. UserP2只能读/写P2。

Now how can I copy a file from one folder to the other? 现在如何将文件从一个文件夹复制到另一个文件夹?

So far I insisted on File.Copy and some sorts of impersonation but no positive results... All I get is "Access Denied"... 到目前为止,我坚持使用File.Copy和一些模拟功能,但没有取得积极的结果...我得到的只是“访问被拒绝” ...

Details: 细节:

  • Files being copied can reach 20gb 复制的文件可以达到20GB
  • The network path may point to "\\localhost\\c$" 网络路径可能指向“ \\ localhost \\ c $”
  • This is a "server-side" app, which means hundreds of requests will be handled each second... reading files to memory, switching credentials, writing will has been considered as a last resort due to obvious scaling issues... 这是一个“服务器端”应用程序,这意味着每秒将处理数百个请求...由于明显的扩展问题,将文件读取到内存,切换凭据,写入将被视为万不得已...

With the specified constraints you do not have many options. 使用指定的约束,您没有太多选择。

One possibly better option than "read to memory / switch credentials / write" would be to do the following: 比“读取内存/切换凭据/写入”更好的选择是执行以下操作:

Read the file (say from Share 1 as UserP1) in chunks while writing to a third, perhaps local, location that both UserP1 and UserP2 has access to. 批量读取文件(例如,从Share 1作为UserP1从Share 1中读取),同时写入UserP1和UserP2都可以访问的第三个(也许是本地)位置。 Then read the file from that location as UserP2 and write to Share 2. 然后从该位置读取文件作为UserP2并写入共享2。

If you have the ability to do this in a multi-threaded fashion you could have UserP2 start reading the file as UserP1 is writing to it. 如果您有能力以多线程方式执行此操作,则可以让UserP2在UserP1写入文件时开始读取文件。 This way you would not have to finish waiting on the writing to the third location to finish before starting the copying to Share 2. You would incur the penalty of the storage needed for the third location, but neither the memory penalty of reading the whole file to memory, nor the time penalty of first copying the entire file to the third location before starting to write to Share 2. 这样,在开始复制到共享2之前,您不必等待到第三个位置的写操作就完成了。您将招致第三个位置所需的存储空间的损失,但是不会读取整个文件内存,也不会在开始写入Share 2之前先将整个文件复制到第三个位置所花费的时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM