Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
37k views
in .NET FTP by (1.9k points)
Hi,
FTP Synchronizer is a great tool. However, I can never get it to work. I am using VB 2005 .NET 2.0. And I started by running it from the example viewer. The example runs and connect to the server, but when I click on "synchronize", I get a lot of errors. The error reads as follows:

- Could not get file modification time. (code 550) "I get 5 pop up messages boxes of this type after clicking synchronize."
- Error - System reference not set to an instance of an object .... "then a lot of exception details."



My second question is, can I do the synchronization tasks at run time in my code rather than in GUI. I want to sun synchronization to almost 200 ftp servers in a loop.

Thanks

38 Answers

0 votes
by (1.9k points)
Hello,

I just tried the new methods and have faced the following issue. I handled the SynchronizingFile event to track individual file that are being synchronized and their associated actions. To do that I am handling the SynchronizingFile event. The problem is that when looking at the event arguments I have e.RemoteFile.Name and e.LocalFile.Name. How can I reference the file that is being synchronized rather than the file according to its location. The error I am getting is NullReferenceException: "Object reference not set to an instance of an object."

It happens when I attempt to reference e.LocalFile.Name while it exists on the Remote path.

and also

when I attempt to reference e.RemoteFile.Name while it exists on the local path.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim conn As New EnterpriseDT.Net.Ftp.ExFTPConnection
        conn.UserName = "user"
        conn.Password = "pass"
        conn.ServerAddress = "1.1.0.4"

        conn.Connect()
        conn.ChangeWorkingDirectory("/files/")
        Dim Rules As FTPSyncRules = New FTPSyncRules
        Rules.Direction = TransferDirection.UPLOAD
        Rules.TransferNewOnly = True
        Rules.IgnoreDate = True
        Rules.FileNameFilter = "*.*"

        AddHandler conn.SynchronizingFile, AddressOf SyncingFile
        AddHandler conn.Synchronizing, AddressOf Syncing
        AddHandler conn.Synchronized, AddressOf SyncDone

        conn.Synchronize(Rules, "e:\myfiles", conn.ServerDirectory)

    End Sub


    Private Sub SyncDone(ByVal sender As System.Object, ByVal e As EnterpriseDT.Net.Ftp.FTPSyncEventArgs)

        Dim conn As ExFTPConnection = DirectCast(sender, ExFTPConnection)
        conn.Close()
    End Sub


    Private Sub SyncingFile(ByVal sender As System.Object, ByVal e As EnterpriseDT.Net.Ftp.FTPSyncFileEventArgs)

        Console.WriteLine("{0} sync action is {1}", e.LocalFile.Name, e.Action.ToString)

    End Sub




I also noticed that the LocalDirectory and RemoteDirectory .size property always returns 0.


This is all what I have write now. Please advise.

Thanks
0 votes
by (1.9k points)
Hello,

In terms of events I think you need to add an event to return arguments relating to the files that will be synchronized. Like in the GUI control, you get a selection on files matching the synch rules. In run-time I will also need that. I basically wish to return the following:

1- Total number and name of files to be synched
2- Total number and name of files successfully synchronized
3- Total number and name of file failed to synchronize. (eg. timeouts, network issues, bad password, etc.)

When done I will need to update the GUI with all that. Ultimately I will use incorporate this into a multithreaded code to loop through 100+ of FTP servers.

Thanks
0 votes
by (51.6k points)
The error I am getting is NullReferenceException: "Object reference not set to an instance of an object." It happens when I attempt to reference e.LocalFile.Name while it exists on the Remote path.


Yes, when either of the files doesn't exist then the property that references it will be null. For example, if the remote file exists but the local files doesn't then e.RemoteFile will be set but e.LocalFile will be null. This is by design. I guess a couple of flags on the event-args called something like LocalFileExists and RemoteFileExists would be useful.

I also noticed that the LocalDirectory and RemoteDirectory .size property always returns 0.


Yes, the Size property for directories has always been zero, but in this case we actually can calculate the total size of the directory so it is actually feasible to set it. Good idea. We'll do that.

- Hans (EnterpriseDT)
0 votes
by (51.6k points)
In terms of events I think you need to add an event to return arguments relating to the files that will be synchronized. Like in the GUI control, you get a selection on files matching the synch rules. In run-time I will also need that. I basically wish to return the following:
  1. Total number and name of files to be synched
  2. Total number and name of files successfully synchronized
  3. Total number and name of file failed to synchronize. (eg. timeouts, network issues, bad password, etc.)


Can't you already do all that with the SynchronizeFile event? The Action property holds the action that the sync-rules have indicated. If you don't change it then that is what is done.

- Hans (EnterpriseDT)
0 votes
by (1.9k points)
Hi,

Well, yes this can be done using the synchronizingFile event. However in order to get the total number of files I have to actually e.RemoteDirectory.FileName to an array list then set the e.action to none. Then rerun the syn again without changing the action!

At least this is what I thought of in case I want to get the total number of files before actually proceeding. I usually do that to manage a progress bar on the GUI. I need to account for the total files then track the successful and failed uploads after the synchronization completes.

On the other side, I am having troubles with synchronization error handling and events firing . You can reproduce one by disconnecting your connection while an upload in progress. In my code below I added the statement
AddHandler conn.Error, AddressOf OnConnError
to catch errors. Anyway, after the error here is what happens:

    - The IOException is thrown back to conn.Synchronize(Rules, "e:\myfiles", conn.ServerDirectory) and never to OnConnError event. - Synchronization completed event [code]SyncDone is called, and signals a completion. - conn.Synchronize(Rules, "e:\myfiles", conn.ServerDirectory) - There is no way to account for a file's synchronization failure.






As I mentioned in an earlier post http://www.enterprisedt.com/forums/viewtopic.php?t=2620. I believe Upload Completed should not be fired if an error has occurred. Or at least it can be fired with a an event argument referencing the filename and any relevant information. obviously the same applies here, SyncCompleted is fired even if an error occurs.


Let me know if you can help.
Thanks
0 votes
by (51.6k points)
OK, I see what you mean about wanting to know how many files are going to be synchronized before the actual synchronization actions are executed.

How about if we change it so that all of the SynchronizingFile events are triggered BEFORE any of the actions are executed and BEFORE the Synchronizing event is triggered? That way you can collect any information you require in the SynchronizingFile event-handler and use it in the Synchronizing event-handler. This gives you a lot of control because you will know all the actions and all of the file-names before the actions are executed, which you can use to provide really detailed feedback to the user.

With respect to the error-handling, the latest version of edtFTPnet/PRO has two new properties, Succeeded and Exception, on most of the event-arg classes. You can use these to find out whether or not the operation succeeded and, if not, what the error was. We've just released this so you might like to download it from here.

- Hans (EnterpriseDT)
0 votes
by (1.9k points)
Hello,


Any news on the last modifications?

Thanks
0 votes
by (51.6k points)
Actually, I was waiting for some feedback, but I gather you agree with them so we'll go ahead and implement them. We're tied up with some other work at the moment, but should have it done by early next week.

- Hans (EnterpriseDT)
0 votes
by (1.8k points)
I've been playing around with the FtpSynchronize function the last few days and I have a few questions:
- how are time zone differences handled when checking for last modified time?
- how can synchronization result be obtained when doing the synchronization in a synchronous way?
- could somebody confirm that the DeleteIfSourceAbsent flag does not work? It seems to have no influence.
- how does the DeleteOnFailure function work? I guess when transferring fails, deleting won't work either...

Also I get an error "Unexpected null reply received". Does anybody else get that?
I'm currently trying to find where its origin lies. Debugging a service is a pain as it seems only to happen on a certain ftp host from a certain server.
Knowing what could possibly cause this reply could probably point me in the right direction.
In an older post I read it happened in the connect method, but it is not in my case.
0 votes
by (162k points)
1. You can set the FTPSyncRules to ignore dates, but the time zone currently is not taken into account. Note that if you set the SynchronizingFile event, you have complete control and can easily decide to take time zones into account.

2. See other post.

3. DeleteIfSourceAbsent should work. Do you follow what it does?

4. DeleteOnFailure - if set to true and an error occurs, the partially written file is deleted.

Unexpected null reply generally means the server has terminated your connection.

Categories

...