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

Advertisement

Moneyblind
Guest

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

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.

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:

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;
}
}

Reply with quote

Advertisement

MichaelMotes
Guest

Same problem

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

Reply with quote

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

Re: Same problem

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.

Reply with quote

Advertisement

MichaelMotes
Guest

XP only

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. :cry: :x :roll: :wink: :P :lol: I get carried away with emoticons. :D

Reply with quote

Gurmeet
Guest

System.TypeInitializationException

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();
}

Reply with quote

Advertisement

Victor78
Guest

Shitty WINSCP

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

Reply with quote

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

Re: System.TypeInitializationException

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.

Reply with quote

Advertisement

You can post new topics in this forum