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?