Setting Working Directory Not Working as Expected

Advertisement

smithochris
Guest

Setting Working Directory Not Working as Expected

I have the following code to start the WinSCP process - this is being called in an SSIS C# script component:

Process winscp = new Process();
string logName = Dts.Variables["User::XMLLogLocation"].Value.ToString();

// Set the executable path and download directory
winscp.StartInfo.FileName = Dts.Variables["$Package::pWinSCPLocation"].Value.ToString();
winscp.StartInfo.WorkingDirectory = Dts.Variables["$Package::pDownloadDir"].Value.ToString();

// Set static execution options (these should not need to change)
winscp.StartInfo.UseShellExecute = false;
winscp.StartInfo.RedirectStandardInput = true;
winscp.StartInfo.RedirectStandardOutput = true;
winscp.StartInfo.CreateNoWindow = true;
winscp.StartInfo.Arguments = "/xmllog=\"" + logName + "\"";

Then the program runs a "synchronize local..." command to grab the appropriate files.

The issue I'm having is that the sync copies the new files to a directory that is different than what I've set in winscp.StartInfo.WorkingDirectory = Dts.Variables["$Package::pDownloadDir"].Value.ToString();

Any ideas on where/how the directory is changing? It goes 1 level deeper in the folder structure than I am specifying.

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,378
Location:
Prague, Czechia

Re: Setting Working Directory Not Working as Expected

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate the session log file, use /log=C:\path\to\winscp.log command-line argument. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Though for now, I will guess that you open a stored site in your script and that site has some local folder set (it's not recommended to use stored sites in scripting).

Btw, as you use C#, you should switch to WinSCP .NET assembly:
https://winscp.net/eng/docs/library
https://winscp.net/eng/docs/library_ssis

Reply with quote

Advertisement

You can post new topics in this forum