Topic "SFTP - Win7 - .tmp The process cannot access the file"

Author Message
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
i m trying to upload file using following code but getting error below


some notes:

i m using windows 7. using crushFTP sftp server, able to connect with using filezilla and winscp client but through code its being nightmare


error/exception
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll

Additional information: The process cannot access the file 'C:\Users\xxxxxxx\AppData\Local\Temp\wscp0D64.036B20B7.tmp' because it is being used by another process.


my code to connect is below

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "127.0.0.1", //hostname e.g. IP: 192.54.23.32, or mysftpsite.com
UserName = "xxxxxx",
Password = "yyyyyy",
PortNumber = zzzzz, //some number
SshHostKeyFingerprint = "ssh-rsa 1024 ::::04:85:3b:7a::::::::"

};

using (Session session = new Session())
{

session.Open(sessionOptions); //Attempts to connect to your sFtp site
//Get Ftp File
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary; //The Transfer Mode -
//<em style="font-size: 9pt;">Automatic, Binary, or Ascii
transferOptions.FilePermissions = null; //Permissions applied to remote files;
//null for default permissions. Can set user,
//Group, or other Read/Write/Execute permissions.
transferOptions.PreserveTimestamp = false; //Set last write time of
//destination file to that of source file - basically change the timestamp
//to match destination and source files.
transferOptions.ResumeSupport.State = TransferResumeSupportState.Off;

TransferOperationResult transferResult;
//the parameter list is: local Path, Remote Path, Delete source file?, transfer Options
transferResult = session.PutFiles(@"C:\Adnan\a.txt", "/", false, transferOptions);
//Throw on any error
transferResult.Check();
//Log information and break out if necessary
}
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Please attach a full debug log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.DebugLogPath. Submit the log with your post as an attachment. If you do not want to post the log publicly, you can mark the attachment as private.
_________________
Martin Prikryl
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Your duplicate post on stackoverflow.com:
http://stackoverflow.com/questions/28027761/winscp-sftp-win7-tmp-the-process-cannot-access-the-file
_________________
Martin Prikryl
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
I have added the log file as private attachment.


prikryl wrote:
Please attach a full debug log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.DebugLogPath. Submit the log with your post as an attachment. If you do not want to post the log publicly, you can mark the attachment as private.
winscpSftp.log (3.58 KB) Private file

Description: log file

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Again, this is not a debug log. It's a session log. Please set also Session.DebugLogPath, not only Session.SessionLogPath. Please, attach both logs.
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
Thanks for your response.

When I set DebugLogPath like below
session.DebugLogPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\debugwinscpSftp.log";

I get following exception
Additional information: The specified registry key does not exist.

prikryl wrote:
Again, this is not a debug log. It's a session log. Please set also Session.DebugLogPath, not only Session.SessionLogPath. Please, attach both logs.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
Can you post complete information about the exception? (exception type, callstack, exception message)
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
I have attached screenshot, please take a look. hope it helps

prikryl wrote:
Can you post complete information about the exception? (exception type, callstack, exception message)
winscp.png (115.13 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
I need to see the "StackTrace".
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
stack trace produced this only
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)


System.IO.IOException occurred
_HResult=2
_message=The specified registry key does not exist.
HResult=2
IsTransient=false
Message=The specified registry key does not exist.
Source=mscorlib
StackTrace:
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)
InnerException:


prikryl wrote:
I need to see the "StackTrace".
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
adnanaman wrote:
stack trace produced this only
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)

I find this unlikely. Are you sure you expanded the "StackTrace" row on the table?

Anyway, can you try to split your code to:
Code:
string debugLogPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\debugwinscpSftp.log";
session.DebugLogPath = debugLogPath;

And check which line throws the exception?
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
I have attached screenshot for you. I also tried by giving file name rather full path so it generates the file in output folder like session log file but still same response. If you want i can send you whole code (project)


prikryl wrote:
adnanaman wrote:
stack trace produced this only
at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)

I find this unlikely. Are you sure you expanded the "StackTrace" row on the table?

Anyway, can you try to split your code to:
Code:
string debugLogPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\debugwinscpSftp.log";
session.DebugLogPath = debugLogPath;

And check which line throws the exception?
winscp.png (129.28 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
adnanaman wrote:
I have attached screenshot for you. I also tried by giving file name rather full path so it generates the file in output folder like session log file but still same response.

And did you click the drop down button on the right? See attached screenshot.

Quote:
If you want i can send you whole code (project)

Well, you can try. But I believe it's something with your environment, rather than the code.
stacktrace.png (7.5 KB)

Description: (none)

stacktrace.png

adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
When i expand there is no more detail its just one line..

so what could be wrong about environment? Firewall? How can i check


prikryl wrote:
adnanaman wrote:
I have attached screenshot for you. I also tried by giving file name rather full path so it generates the file in output folder like session log file but still same response.

And did you click the drop down button on the right? See attached screenshot.

Quote:
If you want i can send you whole code (project)

Well, you can try. But I believe it's something with your environment, rather than the code.
winscp.png (105.79 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
OK, that's strange.
Can you download a code of the .NET assembly and build your project against it? Maybe you get a stack trace then. And if not, you should be able to step into the DebugLogPath setter to see where it throws.
The code is part of overall source code package of WinSCP.

Not sure about what can be the problem with the environment.
adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
Please take a look on exception screenshot

prikryl wrote:
OK, that's strange.
Can you download a code of the .NET assembly and build your project against it? Maybe you get a stack trace then. And if not, you should be able to step into the DebugLogPath setter to see where it throws.
The code is part of overall source code package of WinSCP.

Not sure about what can be the problem with the environment.
debug location error.png (106.94 KB) Private file

Description: PerformanceCounterCategory[] categories = PerformanceCounterCategory.GetCategories();

is throwing exception

adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
Hi

some how i manage to get debug log... can you please take a look


adnanaman wrote:
Please take a look on exception screenshot

prikryl wrote:
OK, that's strange.
Can you download a code of the .NET assembly and build your project against it? Maybe you get a stack trace then. And if not, you should be able to step into the DebugLogPath setter to see where it throws.
The code is part of overall source code package of WinSCP.

Not sure about what can be the problem with the environment.
debugwinscpSftp.log (37.28 KB) Private file

Description: (none)

adnanaman
[View user's profile]

Joined: 2015-01-19
Posts: 11
Location: United Kingdom
I have attached code also and there are two functions one used winscp and other use other third party dll..

winscp is throwing exception but other is working for same server / credentials



adnanaman wrote:
Hi

some how i manage to get debug log... can you please take a look


adnanaman wrote:
Please take a look on exception screenshot

prikryl wrote:
OK, that's strange.
Can you download a code of the .NET assembly and build your project against it? Maybe you get a stack trace then. And if not, you should be able to step into the DebugLogPath setter to see where it throws.
The code is part of overall source code package of WinSCP.

Not sure about what can be the problem with the environment.
sftp code.txt (6.5 KB) Private file

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24555
Location: Prague, Czechia
OK, that's some progress!

What did you do to get the debug log?
The exception screenshot you posted is a "first chance" exception. It should be caught few lines later and should not make it to you code. Did you try to debug it further to see what happens next?

I have sent you an email with a debug version of WinSCP to address you have used to register on this forum.
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