Page 1 of 1
Strange FTP problem
Posted: Tue Dec 01, 2015 3:05 am
by billhemsley
Hi,
I seem to have come across some very odd behaviour and can't work out how to fix it - or even find a useful workaround.
I am trying to get the contents of a file via FTP, yet strangely I can make it work only if I launch an entirely irrelevant dialog box before the put command (I found this by accident while debugging).
So, running with the first card when the stack opens, the following does not work (it produces no error but the field DataFromServer remains empty):
Code: Select all
on openCard
put "ftp://myUsername:myPassword@myIPAddress/myFilename.txt" into myURL
try
put URL myURL into field "DataFromServer"
catch error theError
answer "ERROR:" && theError
end try
end openCard
But the following works fine (the only difference being line 2):
Code: Select all
on openCard
answer "Hello world!"
put "ftp://myUsername:myPassword@myIPAddress/myFilename.txt" into myURL
try
put URL myURL into field "DataFromServer"
catch error theError
answer "ERROR:" && theError
end try
end openCard
I've tested this in a stack containing nothing but this script and the one field on a single card (but using a real URL), so there's not much that could be interfering with it.
I've tried it with an HTTP URL, and the first version works fine.
In the development environment, I can also make the first version work by closing the stack (keeping it in memory) and reopening.
Any help would be most gratefully received!
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 3:48 am
by Simon
Hi Bill,
Maybe this has to do with the loading of the internet libraries?
You can try sending after a time period;
Code: Select all
on openCard
send "getMyFtp" to me in 10 millisecs
end openCard
on getMyFtp
put "ftp://myUsername:myPassword@myIPAddress/myFilename.txt" into myURL
try
put URL myURL into field "DataFromServer"
catch error theError
answer "ERROR:" && theError
end try
end getMyFtp
Simon
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 10:39 am
by AndyP
Hi Bill,
Agree, probably the internet libraries have not fully loaded.
Try adding a wait 1 second after the openCard handler.
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 12:37 pm
by billhemsley
Hi Simon, Andy,
Thanks for the replies.
Simon's solution seemed to work for a couple of runs, but has now stopped working. And it seems Andy's method (inserting a simple wait for a second - even or a few seconds) doesn't work - but given the intermittent nature of the problem, I'm not sure how much this means.
I tried each version with an HTTP URL, and it always worked. And pasting the FTP URL into a browser works fine too, so the URL is correct and there aren't problems on the server. So the problem does seem to be with FTP in LC.
I note that I got a couple of really bad crashes while testing, corrupting the test stack and needing a machine re-start before I could run LC again.
I'll try again on a different machine in a different building and will report back - though I'm not holding out any great hope on this helping!
Meanwhile, if anyone has any other suggestions...
Bill
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 6:53 pm
by AndyP
Hi Bill,
Which version of LC are you using? Is it a stable or DP release?
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 7:05 pm
by FourthWorld
You may have stumbled across a bug, and if you're running v8.0 DP10 it may be worth filing a bug report.
But in the meantime, do you need to use FTP? You noted HTTP works well, and using that would avoid having to send you're site's FTP password in plain text. Even if the file is hidden through nothing more than HTTP Basic Authentication it'll be a more secure option: both send passwords in plain text, but Basic Auth only exposes read access to a single folder, as opposed to read/write access to the full FTP site.
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 7:58 pm
by billhemsley
I'm running 7.1 Stable. I'm beginning to suspect a bug myself.
More testing indicates the following:
Code: Select all
#THIS WORKS
on openCard
send "getMyFtp" to me in 10 millisec
end openCard
on getMyFtp
--FTP stuff goes here
end getMyFtp
Code: Select all
#THIS ALSO WORKS - YES, THAT'S ZERO MILLISEC!
on openCard
send "getMyFtp" to me in 0 millisec
end openCard
on getMyFtp
--FTP stuff goes here
end getMyFtp
Code: Select all
#BUT THIS DOES NOT WORK
on openCard
send "getMyFtp" to me
end openCard
on getMyFtp
--FTP stuff goes here
end getMyFtp
Code: Select all
#THIS WORKS, BUT IT SEEMS UNSTABLE
on openCard
getMyFtp
end openCard
on getMyFtp
answer "Hello world!"
--FTP stuff goes here
end getMyFtp
I'll give it a try in v8.0 DP10 and see if the problem is still there, and report back.
And for my current project, I think I'll take the good advice from @FourthWorld and go the HTTP route.
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 8:31 pm
by FourthWorld
Given the mix of cases where it works and where it doesn't, it seems this may be caused by the Internet library (libURL) needing to finish initializing itself during startup, which it seems from the examples happens during first idle.
This assumes that the openCard handler you have is for the first card in you mainstack - if not we'd need to look at other solutions.
It may be that this could be fixable in v8.0, but it may also have to wait until libURL is rewritten (scheduled for post-8.0 as part of the Kickstarter goals).
In the meantime, is there any downside to using the "send...in 0 millisecs" option? The reason that helps here is that LC timers work very much like timers in JavaScript and other single-threaded scripting engines, in which a queued message doesn't interrupt any current processing once the specified time has elapsed, but merely queues it to be fired at first available idle after that moment. Unless you have some long-running process it'll usually fire at the specified moment, but if another handler is running when that moment occurs the running handler will complete first before the timer event triggers. When using 0 as the interval, it basically just tells the engine to use first available idle.
PS: Unless this is limited to use an an intranet I'd still go with HTTP, not just because it's a bit faster but mostly for the benefit of reducing potential security exposure. FTP is useful on intranets, but IMO too dangerous to use on the Internet.
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 10:28 pm
by billhemsley
It is indeed the first card of the stack. I'm loading data for the stack to work with.
Very interesting about timers and queued messages, and yes, "send...in 0 millisecs" should provide a good workaround for now.
I entirely agree about FTP. The application is currently for very limited use and FTP is convenient. However, the final product will be accessing data from Django via HTTP.
My brain being rather frazzled by the whole thing, I filed this as Bug 16525 before checking with LC 8.0 DP10. However, I've tried now, and the problem seems to have gone away, so I've added a note to the bug report to that effect.
Many thanks for all the help.
Re: Strange FTP problem
Posted: Tue Dec 01, 2015 10:51 pm
by FourthWorld
Django - nice! Someone I work with has been after me to learn it, and while I've barely scratched the surface so far I like what I see.
Do you use Python much? I ask because I've been itching to do some comparative benchmarks between Python and LiveCode, but my Python skills are virtually nonexistent and good benchmarks would require that both languages be used well.
If such a thing interests you I'd welcome the collaboration. Probably needn't be very deep, just a few tasks with string manipulation, arithmetic, etc.
Re: Strange FTP problem
Posted: Wed Dec 02, 2015 6:26 pm
by billhemsley
The bug has been confirmed as existing in LC 6.7.x and 7.x and having been fixed in 8.
Regarding LC vs Python, this is something I'd be very interested in myself. I've produced a number of applications where I've just assumed Python was faster, and used LC as a front end. I've never got a proper handle on where the LC should stop and the Python begin - though I'm sure it should sometimes begin somewhere for some things. I certainly can't claim to be any sort of Python expert, but have been using it for a couple of decades so have a fair idea of the standard/efficient Pythonic ways of going about the basic tasks. I'm pretty busy over the next few months, but I'm sure I could find a few hours for an interesting side project. You can find my details at arkesis.co.uk/contact.