Topic "extra path getting appeneded while uploading a file in .net"

Author Message
SV999

Guest


I am using winscp5.1 and I am trying to automate downloading and uploading a file through sharepoint using the winscp .net automation dll. I was able to sucessfully download the file. But while uploading the file, It is appending an extra path to the actual path where the file has to be uploaded. Due to this it fails. This happens in the sharepoint code. I copied the same code to a console application and it runs fine. I don't know why it is appending the extra path in sharepoint.

This is my code present both in sharepoint and in the console app.

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp, //sftp
HostName = settings.HostName, //hostname
UserName = settings.UserName, //username
Password = settings.Password, //password
SshHostKeyFingerprint = settings.FingerPrint, //fingerprint
PortNumber = settings.Port, //22
};

using (Session _session = new Session())
{
_session.ExecutablePath = settings.WinScpPath; //c:\winscp\winscp.exe

//_session.SessionLogPath = "C:\\SftpDownload\\upoadSessionlog.txt";
//_session.DebugLogPath = "C:\\SftpDownload\\uploadDebuglog.txt";

// Connect

_session.Open(sessionOptions);

if (File.Exists(settings.LocalPath))
{
// Get files
TransferOptions _transferOptions = new TransferOptions();
_transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult _transferResult;
_transferResult = _session.PutFiles(settings.LocalPath, settings.RemotePath, false, _transferOptions);

//setting.localpath= c:\\foo\foo.txt
//settings.Remotepath=/data/projects/foo/

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

// Print results
_status.Result = true;
_status.UserMessage = String.Format("Uploaded {0}", settings.LocalPath);
}
else
{
_status.Result = false;
_status.ErrorMessage = String.Format("Could not find file {0} or get its attributes. Please verify path/filename", settings.LocalPath);
}


This code works fine in a console app,but when i put this code into sharepoint, then at runtime, when _transferResult.Check() is called, it adds some path extra to the remote path like "/xyz/dummy/ /data/projects/foo/" . As you can see, "/xyz/dummy/ " is the extra path and i get an error

Cannot create remote file '/xyz/dummy/ /data/projects/foo/foo.txt.filepart'


I don't understand how the same code works in console but not in sharepoint. I feel that the path "/xyz/dummy/ " is the home directory of the sftp server. Cansomebody tell me how to get out of this problem? I have tried adding fresh assembly to GAC, referencing dlls afresh and restarting IIS, but no use.
Does the dll cache the path?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25018
Location: Prague, Czechia
Please attach or email me both Session.SessionLogPath and Session.DebugLogPath
_________________
Martin Prikryl
SV999

Guest


Thanks . This issue is fixed. It seems to be working now and It seems to be because there was a space in the starting of the path mentioned. i.e.
' /data/projects/foo/'. Thanks again.
cm2pt

Guest


I have an issue when trying to run a powershell script on Task Scheduler to verify the existence of a file in a SFTP server using WINSCP. When I run with the option "Run only when user is logged on" on task scheduler everything runs fine.
The problem comes when I change to the option "run whether user is logged on or not". As soon as I run the script after changing that option I get the following message when doing the session.open command:

"
Exception: WinSCP.SessionLocalException: WinSCP process terminated with exit code 3 and output "", without responding (response log file D:\Logs\WinSCP\LOG_WINSCP_XML_20140324_201253.log was not created). This could indicate lack of write permissions to the log folder or problems starting WinSCP itself.
at WinSCP.Session.Open(SessionOptions sessionOptions)
"

I've tried changing the debug, session and xml log path. It never created the XML log and the session one only creates when the code runs successfully.
I've updated WinSCP to the latest version (5.5.2).

The code I'm using is:
# Setup session options
$sessionOptions = New-Object WinSCP.SessionOptions
$sessionOptions.Protocol = [WinSCP.Protocol]::SFTP
$sessionOptions.HostName = "***"
$sessionOptions.UserName = "***"
$sessionOptions.Password = "***"
$sessionOptions.SshHostKeyFingerprint = "***"

$session = New-Object WinSCP.Session

$session.DebugLogPath = $WinSCPDebugLogFile
$session.SessionLogPath = $WinSCPSessionLogFile
$session.XMLLogPath = $WinSCPXMLLogFile

"3" | Out-File $LogFile -Append -Force

try
{
# Connect
$session.Open($sessionOptions)

Can you help me understand what the problem is?
LOG_WINSCP_DEBUG_20140324_201253.log (22.88 KB) [Download]

Description: (none)

martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25018
Location: Prague, Czechia
cm2pt wrote:
The problem comes when I change to the option "run whether user is logged on or not". As soon as I run the script after changing that option I get the following message when doing the session.open command:

"
Exception: WinSCP.SessionLocalException: WinSCP process terminated with exit code 3 and output "", without responding (response log file D:\Logs\WinSCP\LOG_WINSCP_XML_20140324_201253.log was not created). This could indicate lack of write permissions to the log folder or problems starting WinSCP itself.
at WinSCP.Session.Open(SessionOptions sessionOptions)

Exit code 3 is often caused by this problem:
https://winscp.net/tracker/show_bug.cgi?id=996
Did you use the assembly often before with old version of WinSCP?
Consider restarting your machine.
Let us know if it does not help.
cm2pt

Guest


I saw on another thread that a restart was needed after the update of WinSCP. After we did that is works fine.
Can I ask another question on a different topic?

I have a script that goes every 5 minutes check on the server if a file exists. The server closes the connection in the meanwhile and I get the error "Exception: WinSCP.SessionLocalException: Element "group" not found in the log file." when running the FileExists for the third time.
Is there any option to reconnect? I've tried using the Opened property in the Session without any luck.
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25018
Location: Prague, Czechia
cm2pt wrote:
I have a script that goes every 5 minutes check on the server if a file exists. The server closes the connection in the meanwhile and I get the error "Exception: WinSCP.SessionLocalException: Element "group" not found in the log file." when running the FileExists for the third time.

The message will get better in the next major release:
https://winscp.net/tracker/show_bug.cgi?id=1137

Quote:
Is there any option to reconnect? I've tried using the Opened property in the Session without any luck.

No. You need to create new Session instance.
_________________
Martin Prikryl
cm2pt

Guest


I had to include the below code in the beginning of the while clause to make sure a new session is opened when I want to check for the file existence.
It now works.

# Setup session log files locations
$session = New-Object WinSCP.Session
$session.DebugLogPath = $WinSCPDebugLogFile
$session.SessionLogPath = $WinSCPSessionLogFile
$session.XMLLogPath = $WinSCPXMLLogFile

# Connect
$session.Open($sessionOptions)
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