1

Maybe I already said that in the last question...

I have a PHP script that is constantly updating a ZIP file using cronjobs.

While I have a VB.NET application running in the background and it is executed every 900 milliseconds .. This VB.NET application downloads the ZIP file using FTP.

Every time the ZIP file is updated.. I get "(550) File unavailable" error on the VB.NET application, but after I click "Continue" the new file is downloaded successfully.

I searched everywhere to ignore this error and prevent it from displaying but no benefit.

So what to do? The fix is in the PHP code? or the VB.NET code?

I already have a solution which is increasing the VB.NET application Timer to 5000 milliseconds (5 seconds) instead of 900 milliseconds .. But I really see the 900 milliseconds time is suitable because I want the file to be downloaded fastly.

EDIT: Increasing the timer failed, because the timer still might be running and the cronjob is executed at the sametime.

If there's any solutions then that's really great! else, I think the only solution is to increase the VB.NET application Timer, right?

Thanks!

Mario
  • 1,374
  • 6
  • 22
  • 48
  • 1
    900 milliseconds will pass very fast.. im sure that sometimes u wont get the error on the vb.net application and some other times u will get it. thats because if the zip file was updated before the timer starts then everything will go fine .. but if it was updated while the timer is already running, the error will appear. so it is the timer problem .. maybe 5 seconds too are not enough. – protld Aug 30 '17 at 01:30
  • @protld - 100% true! I'm being amazed when I see the ZIP file size was changed but the error didn't appear. I'm waiting for other people's suggestions first, I hope there's a solution other than the Timer increase. (I hope). However thank you very much protld ! :-) – Mario Aug 30 '17 at 01:34
  • The issue is because your doing it too fast, but it seems abit like an XY problem to keep a file updated, not to mention chewing through your bandwidth. Why not directly grab the files from the source or build the zip file and then proxy it. Perhaps even check there are new files to add before doing updates.. there are even libs like flysystem which can help you cache a file. – Lawrence Cherone Aug 30 '17 at 01:45
  • @LawrenceCherone What you said is very hard for me xD my experience in VB.NET is medium, I know PHP more :/ so changing the Timer interval will solve that? – Mario Aug 30 '17 at 01:49

4 Answers4

1

Yes the only solution is to change the Timer interval.

On the Form Load event write this (Timer1 is an example but u write your timer name):

Timer1.Interval = 5000

however, if u Are using C# you can check if the file exists on the FTP server or not ..... and if the file does not exists then the timer won't execute ! but you are using vb dot net

usamember
  • 468
  • 2
  • 5
  • 15
  • im lazy to try that .. however i will do it now :-) I will check that as accepted if it worked after few tests. – Mario Aug 30 '17 at 01:51
  • Increasing the timer failed, because the timer still might be running and the cronjob is executed at the sametime. – Mario Aug 30 '17 at 11:16
1

Any two periodic tasks fighting over a shared resource will eventually encounter a collision. The general strategies for dealing with it are:

  • Retry failed operations until successful

  • Lock the resource in such a way that callers are blocked until the lock is released

In your case, retry seems the easier option, as you can implement it in the client (your VB app). Locking would have to be implemented at the server, and would also involve configuring or customizing the FTP server itself, not just your PHP script.

Increasing the timer only decreases the risk of collision. It doesn't eliminate it.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
0

You can put your code in Try ... Catch and just ignore that error.

Youssef13
  • 3,836
  • 3
  • 24
  • 41
  • You can leave it empty or add "if" condition to make sure the error is 550 File unavailable, and if not, show the error. – Youssef13 Aug 30 '17 at 17:07
0

OK, I solved that! Here is how:

In the PHP file, I added this variable line:

$RandomFileName = rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9).rand(0, 9).".zip";

And I created an empty txt file and named it "lastfilename.txt" and I set the permissions of it to 777 .

After that I added that in the PHP file:

// Clear the content of the "lastfilename.html" file.
file_put_contents("./lastfilename.txt", "");
// Add the new content to the "lastfilename.html" file.
file_put_contents("./lastfilename.txt", $RandomFileName);

Now I added that too in the PHP file:

$GetLastUpdatedFileName = file_get_contents("./lastfilename.txt");
Zip('../MyFolder', '../zipfiles/'.$GetLastUpdatedFileName);

Please note that my PHP script ZIPs "MyFolder" directory and put the ZIP file to the "zipfiles" directory.

I used this answer for the Zip function.

Now in the VB.NET application: I created a Label and named it "LastupdatedFilename" ( I set the Label color to the same color of the Form background to hide it )

And I added this code on the VB.NET application Timer tick:

Dim address As String = "http://tld.com/link/to/textfile.txt"
Dim client As WebClient = New WebClient()
Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
LastupdatedFilename.Text = reader.ReadToEnd

Now the VB.NET application download the file as the following (this is added on the Timer tick code too):

FtpDownloadFile("htdocs/zipfiles/" + LastupdatedFilename.Text)

So yes, it is a waste of the disk space but it is suitable for me.

Summary: I create new ZIP file with new name instead of replacing the old one.

Thanks for everyone who tried to solve my problem :-)

Mario
  • 1,374
  • 6
  • 22
  • 48