The Ftp.TransferProgressChanged
event notifies you about data transfer between the Rebex.Net.Ftp client and the server to which the client is connected. It will not get fired in case of server-to-server transfer as the data are transferred directly between those two FTP servers so there is no transfer between client and server involved.
There is a workaround - connect to the target FTP server with another FTP connection and then monitor the current file size via Ftp.GetFileLength method as you wish.
A simple code example is available here:
void PerformFxpTransferAndReportItsProgress()
{
string fileName = "file.txt";
string fileNameLocal = @"c:\" + fileName;
string primaryServerDest = "/uploadDir1/" + fileName;
string secondaryServerDest = "/uploadDir2/" + fileName;
Ftp ftp1 = new Ftp();
ftp1.Connect("server1");
ftp1.Login("user1", "password1");
Ftp ftp2 = new Ftp();
ftp2.Connect("server2");
ftp2.Login("user2", "password2");
// get file size on source FTP server
long fullLength = ftp1.GetFileLength(primaryServerDest);
// connect to the target FTP server with another client - it will be used to periodacally check for file size during the time
// when server-to-server file transfer is in progress
Ftp ftp3 = new Ftp();
ftp3.Connect("server2");
ftp3.Login("user2", "password2");
Task task;
// perform the server-to-server FXP transfer
task = ftp1.CopyToAnotherServerAsync(ftp2, primaryServerDest, secondaryServerDest).ContinueWith(
(e) =>
{
Console.WriteLine("File '{0}' has been transferred via FXP.", fileName);
return;
}
);
// report progress during FXP operation
while (!task.IsCompleted)
{
long lengthCurrent = 0;
if (ftp3.FileExists(secondaryServerDest))
lengthCurrent = ftp3.GetFileLength(secondaryServerDest);
Console.WriteLine("FXP transfer progress: {0}B out of {1}B has been uploaded.", lengthCurrent, fullLength);
Thread.Sleep(500); // choose your own interval
}
}