.NET Assembly Session.MoveFile Method Problem

Advertisement

Yros
Joined:
Posts:
2
Location:
Rome

.NET Assembly Session.MoveFile Method Problem

Hi,

I'm tring move zip files from one directory to another directory in the same server using by C#.
Despite app doesn't throw any erros, I can move those file, . I've red many articles but I haven't
found clear answer so far. Therefore I'm asking you for help. Below is a code:

try
{

SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = "xxxxxxxxx.xxxxxxxxx.xxx.xx",
UserName = "xxxxxxxxx",
Password= "xxxxxxxxx",
SshHostKeyFingerprint = "ssh-rsa xxx"
};
string fileName = "aaa.zip";
string remotePath = "/sftp/xxxx/xxxxxx/Test" + "/" + fileName;

//string remotePath1 = "/sftp/xxxx/xxxxxx/Test/Archive"; -> doesn't work
//string remotePath1 = "/sftp/xxxx/xxxxxx/Test/Archive" + "/"; -> doesn't work
string remotePath1 = "/sftp/xxxx/xxxxxx/Test/Archive" + "/" + fileName; // -> doesn't work

using (Session session = new Session())
{
session.Open(sessionOptions);
Console.WriteLine("\nFrom here:\n{0}\nto here:\n{1}\n", remotePath, remotePath1);

if (session.FileExists(remotePath))
session.MoveFile(remotePath, remotePath1);
}

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

I guess It might be sth wrong with remotePath1, and I tred diferent combination of the remotePath1. Unfortunately, all of them failed. May be you have got better ideas?

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
40,567
Location:
Prague, Czechia

Re: .NET Assembly Session.MoveFile Method Problem

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.

Reply with quote

Yros
Joined:
Posts:
2
Location:
Rome

Re: .NET Assembly Session.MoveFile Method Problem

Problem's partly been solved.

Method works fine. I've just discovered that file was transfered. However I have to press Refresh button in both directories(remotePath, remotePath1) to see it.

So another question is how to refresh sesion automaticly after the transfer?

Reply with quote

Advertisement

You can post new topics in this forum