Topic ".NET Assembly Session.MoveFile Method Problem"

Author Message
Yros
[View user's profile]

Joined: 2015-06-02
Posts: 2
Location: Rome
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?
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
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.
Yros
[View user's profile]

Joined: 2015-06-02
Posts: 2
Location: Rome
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?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25034
Location: Prague, Czechia
You use the script as a custom command from WinSCP?
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