Topic "Syncronize Vs GetFiles C#"

Author Message
Andrezinn
[View user's profile]

Joined: 2012-04-10
Posts: 4
Here I am, after try alot of different thinks, asking you guys if someone could please help me.

Today I have this script:
option batch on
option confirm off
open XXXX:YYYY@ZZZ.WWW.KKK.QQQ:7001
cd "ROOT"
synchronize local "J:\FILES" "/ROOT/Jan"

And I am trying to do this Syncronyze code, using C# as follow:

// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = Ip,
UserName = User,
Password = Pwd,
PortNumber = Convert.ToInt32(Port),
SshHostKey = "ssh-rsa 1024 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx"
};

using (Session session = new Session())
{
//Desabilita o check de verses
session.DisableVersionCheck = true;
// Will continuously report progress of synchronization
session.FileTransferred += FileTransferred;
// Connect
session.Open(sessionOptions);

RemoteDirectoryInfo directory = session.ListDirectory(cEntrada[0]);
foreach (RemoteFileInfo fileInfo in directory.Files)
{
listBox1.Items.Add("Name: " + fileInfo.Name + " length:" + fileInfo.Length + " Permissions:" + fileInfo.FilePermissions + " Wrote in " + fileInfo.LastWriteTime);


// ****************************************************
// UNTIL HERE, IT IS OK!
// ****************************************************

//Arrow It suppose to work as we have in WinScp example:
SynchronizationResult synchronizationResult;
synchronizationResult = session.SynchronizeDirectories(SynchronizationMode.Local, cEntrada[0], cSaida[0], false);
synchronizationResult.Check();

// But Just didnt bring me anything.... Question
// In another hand, If I try

TransferOperationResult transferResult;
transferResult = session.GetFiles(cEntrada[0], cSaida[0], false);
transferResult.Check();

// It start to download my files... but I have more than 100 files day, and I really dont want to download all of then everytime.
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Should be:
synchronizationResult = session.SynchronizeDirectories(SynchronizationMode.Local, cSaida[0], cEntrada[0], false);
Andrezinn
[View user's profile]

Joined: 2012-04-10
Posts: 4
prikryl,
Than you for your help, but nothing happens... it still pass thru this line as if I dont have it

I also have my:
private static void FileTransferred(object sender, TransferEventArgs e)

And once again, my code never enter on it
Andrezinn
[View user's profile]

Joined: 2012-04-10
Posts: 4
It was a stupid error in my path cSaida[0]. Rolling Eyes

cSaida[0] = "J:\Test\Files from Jan\Folder1"

and in Windows I had
"J:\Test\Files from Jan\"
Thank you!

Now I need to know how to capture these events by the "FileTransferred" as the link
http://winscp.net/eng/docs/library_session_synchronizedirectories#example
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
Andrezinn wrote:
Now I need to know how to capture these events by the "FileTransferred" as the link
http://winscp.net/eng/docs/library_session_synchronizedirectories#example

Let me know if you need any help with this.
_________________
Martin Prikryl
Andrezinn
[View user's profile]

Joined: 2012-04-10
Posts: 4
prikryl,
To be honest, It is working kind well. I just don't know how can I (if I can) watch my download % for each file, and\or my % of files download.

In this second case I tryed:

int contador = 0;
label1.Text = "Listing";
foreach (RemoteFileInfo fileInfo in directory.Files)
{
contador++;
}
progressBar1.Maximum = contador;


and in my FileTransferred Method
progressBar1.Value++;

But it just work for the first Path (Of course, I couldnt retrieve my subfolders... since I start my session.SynchronizeDirectories, it freeze my code)

Could you help me with it?
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 24512
Location: Prague, Czechia
With synchroniztion there's no way to calculate progress. WinSCP does not accounce how many files it's going to synchronize.
_________________
Martin Prikryl
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