简体   繁体   中英

Copy File Edge Case

I have a app running under UserX. I also have 2 network paths that point to subfolder of the same Share, like:

  • P1 = \\\\MyMainShare\\share\\Folder 1
  • 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. UserP1 can read/write P1 only. UserP2 can read/write P2 only.

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"...

Details:

  • Files being copied can reach 20gb
  • The network path may point to "\\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. Then read the file from that location as UserP2 and write to Share 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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