Topic "SFTP Connection - Session.Open; ERROR: Temporary File in use"

Author Message
Moneyblind

Guest


Hello! I am running into an issue; I have taken the overall example C# code and modified it to match my credentials and host account. However, the TEMPORARY file that is created by Session.Open is returning this error.

Code:
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file 'C:\Users\Admin\AppData\Local\Temp\wscp24C0.0223CC89.tmp' because it is being used by another process.


Here is the code:

Quote:

private bool uploadFile(string path, string hostName, string username, string password)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = hostName,
UserName = username,
Password = password,
SshHostKeyFingerprint = "ssh-rsa 1024 **:**:**:**:20:8f:95:69:12:f5:52:**:**:**:**:**"
};

using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);

// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;

TransferOperationResult transferResult;
transferResult = session.PutFiles(path, "/", false, transferOptions);

// Throw on any error
transferResult.Check();

// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}

return true;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return false;
}
}
Advertisements
Moneyblind

Guest


This is where the error is thrown;

// Connect
session.Open(sessionOptions);
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25019
Location: Prague, Czechia
Please post a callstack of the extension.
_________________
Martin Prikryl
MichaelMotes

Guest


I have this same problem, here is the callstack:
mscorlib.dll!System.IO.__Error.WinIOError(int errorCode, string maybeFullPath) + 0x321 bytes
mscorlib.dll!System.IO.FileStream.Init(string path, System.IO.FileMode mode, System.IO.FileAccess access, int rights, bool useRights, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES secAttrs, string msgPath, bool bFromProxy, bool useLongPath) + 0x477 bytes
mscorlib.dll!System.IO.FileStream.FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) + 0x54 bytes
mscorlib.dll!System.IO.File.Open(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) + 0x25 bytes
WinSCPnet.dll!WinSCP.SessionLogReader.OpenLog() + 0xd1 bytes
WinSCPnet.dll!WinSCP.SessionLogReader.DoRead() + 0x64 bytes
WinSCPnet.dll!WinSCP.SessionLogReader.Read(WinSCP.LogReadFlags flags) + 0x86 bytes
WinSCPnet.dll!WinSCP.CustomLogReader.TryWaitForNonEmptyElement(string localName, WinSCP.LogReadFlags flags) + 0x5f bytes
WinSCPnet.dll!WinSCP.CustomLogReader.WaitForNonEmptyElement(string localName, WinSCP.LogReadFlags flags) + 0x29 bytes
WinSCPnet.dll!WinSCP.CustomLogReader.WaitForNonEmptyElementAndCreateLogReader(string localName, WinSCP.LogReadFlags flags) + 0x29 bytes
WinSCPnet.dll!WinSCP.Session.Open(WinSCP.SessionOptions sessionOptions) + 0x775 bytes
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25019
Location: Prague, Czechia
Thanks for your report.

Can you send me an email, so I can send you back a debug version of WinSCP to track the problem? Please include link back to this topic in your email. Also note in this topic that you have sent the email. Thanks.

You will find my address (if you log in) in my forum profile.
_________________
Martin Prikryl
MichaelMotes

Guest


This error only occurs on my old XP dev machine. My new Win7 dev machine doesn't experience any issue with the same code. I suppose XP is official dead and dying. Crying or Very sad Mad Rolling Eyes Wink Razz Laughing I get carried away with emoticons. Very Happy
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25019
Location: Prague, Czechia
I have sent you an email.
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
I am having the same exception but on windows 7... i have described my issue here https://winscp.net/forum/viewtopic.php?t=14755

prikryl wrote:
I have sent you an email.
Gurmeet

Guest


Hi,
This is happening when I am trying to compile VS 2013 solution
System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Additional information: The type initializer for 'XXXXX' threw an exception.

using (Session sess = new Session())
{
//sess.SessionLogPath = @"C:\GUR";
sess.Open(sessionOptions);

//Get Ftp File
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary; //The Transfer Mode -
transferOptions.FilePermissions = new FilePermissions(0666); //Permissions applied to remote files. 0666 is read/write
transferOptions.PreserveTimestamp = false; //Set last write time of
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;

TransferOperationResult transferResult;
transferResult = sess.PutFiles(fileName, ConfigurationManager.AppSettings["SFTPToPath"], false, transferOptions);

transferResult.Check();
}
Victor78

Guest


Fack you guys who made this shity winscp, I'm lost my 2 weeks job because i' used this crap program.
Isn't save anything just after few try because this is the full of Shlt software
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25019
Location: Prague, Czechia
Gurmeet wrote:
Hi,
This is happening when I am trying to compile VS 2013 solution
System.TypeInitializationException was unhandled
Message: An unhandled exception of type 'System.TypeInitializationException' occurred in mscorlib.dll
Additional information: The type initializer for 'XXXXX' threw an exception.

What is the XXXX? Anyway, please start a new thread. I do not see how's your problem related to this topic.
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License