копировать файлы с аутентификацией в ядро ​​.net - PullRequest
0 голосов
/ 30 мая 2018

Я создал приложение ядра .net (2.0), которое копирует файл с одного сервера на другой с использованием System.io, которое выглядит следующим образом:

if (!File.Exists(DestinationFullPath)) //copy only if file not exists
{
    try {
        runner.WriteLogs(MethodBase.GetCurrentMethod().ToString(),
            LogLevel.Information, "Start copying file from :{0} to {1} ",
            pFromPath, pToPath);

        File.Copy(file, DestinationFullPath);

        runner.WriteLogs(MethodBase.GetCurrentMethod().ToString(),
            LogLevel.Information, "{0} copied to {1}",
            file, pToPath);

    } catch (Exception) {
        runner.WriteLogs(MethodBase.GetCurrentMethod().ToString(),
            LogLevel.Critical, "Error in copying {0} to {1}",
            file, pToPath);
    }
}

Проблема с ним заключается в том, что при запуске в Linuxконтейнеры, он хочет конкретного пользователя с разрешением.

Я знаю об олицетворении, но не в ядре 2.0, кто-нибудь знает способ его выполнения?

Что-то вроде:

var Impersonation = new XXX();
Impersonation.username = "XXX";
Impersonation.Password = "XXX";
Impersonation.Domain = "XXX";

Using(Impersonation) {

    //copy only if file not exists
    if (!File.Exists(DestinationFullPath)) {
        try {
            runner.WriteLogs(MethodBase.GetCurrentMethod().ToString(),
                LogLevel.Information, "Start copying file from :{0} to {1} ",
                pFromPath, pToPath);

            File.Copy(file, DestinationFullPath);

            runner.WriteLogs(MethodBase.GetCurrentMethod().ToString(),
                LogLevel.Information, "{0} copied to {1}",
                file, pToPath);

        } catch (Exception) {
            runner.WriteLogs(MethodBase.GetCurrentMethod().ToString(),
                LogLevel.Critical, "Error in copying {0} to {1}",
                file, pToPath);
        }
    }
}
...