Re: Impersonation and WinSCP
You can use
Session.XmlLogPath to make it log to a folder you can write to.
Session.XmlLogPath to make it log to a folder you can write to.
_process.StartInfo.UserName = "secureUserName";
_process.StartInfo.Password = new SecureString();
string passwd = "securePassword";
foreach (char c in passwd)
{
_process.StartInfo.Password.AppendChar(c);
}
_process.StartInfo.Domain = "OurDomain";
WinSCP process terminated with exit code -1073741502 and output "", without responding (response log file C:\Users\loggedinuser\AppData\Local\Temp\8\wscp0C24.035EF4D2.tmp was not created). This could indicate lack of write permissions to the log folder or problems starting WinSCP itself.
dotnet folder of WinSCP source code package).
dotnet\Internal\ExeSessionProcess.cs. By the end of ExeSessionProcess constructor code, where Process instance is created, add
_process.StartInfo.UserName = ...;
_process.StartInfo.Password = ...;
Impersonator impersonator =
new Impersonator("secureUser", "ourDomain", "secureUserPassword");
//
// Other code here runs correctly as 'secureUser'
//
// Then this is running WinSCP as the logged in user. We know this because
// We're getting access denied for the folder on our network that
// we're trying to download to.
// I can also see WinSCP in task manager under the logged in user
// If an admin user logs in then the FTP download works.
using (Session session = new Session())
{
// Connect
session.Open(sessionOptionsForExternalFTPSite);
RemoteDirectoryInfo rd =
session.ListDirectory(sessionOptionsForExternalFTPSite);
RemoteFileInfoCollection rfc = rd.Files;
foreach (RemoteFileInfo rf in rfc)
{
if (rf.Name.Contains(fromFileNameStart))
{
fileList.Add(rf.Name);
}
}
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
transferOptions.FileMask = fileMask;
transferResult =
session.GetFiles(FTPDownloadDir, toFilePath, false, transferOptions);
// Throw on any error
transferResult.Check(); // Access denied error!
}
return fileList; //