Page 1 of 1
FTP access
Posted: Wed Nov 06, 2013 8:20 pm
by bertBUSIbr8
Hi,
I'm developing an Android app for a Samsung Camera, running Jelly Bean, which has to upload images to a [local] ftp server.
Now, before I upload, I want to double check that the prefs are ok and an ftp connection can be established. The gLocation always points to a folder to upload to.
Code: Select all
put "ftp://" & gUser & ":" & gPWD & "@" & gLocation into extFTPURL
However, this always throws an error:
java.io.IOException: Unable to connect to server: Unable to retrieve file: 550
If I change the code to check on the ftp for an test file like:
Code: Select all
put "ftp://" & gUser & ":" & gPWD & "@" & gLocation & "test.txt" into extFTPURL
That works fine, if it's there it continues, if it doesn't it throws the error and warns the user.
Does anyone know if it's possible to make it behave with the folder as it does with the test file, ie. if the folder's there, continue copying. Is there a known reason why a folder should throw an error even if it's there? Or am I using the wrong code to check for the existence of a folder?
Many thanks,
Bert
Re: FTP access
Posted: Wed Nov 06, 2013 11:43 pm
by jacque
You need the "URL" identifier:
Code: Select all
put url "ftp://" & gUser & ":" & gPWD & "@" & gLocation into extFTPURL
It will return the files in the folder.
Re: FTP access
Posted: Thu Nov 07, 2013 10:17 am
by bertBUSIbr8
Hi Jacque,
Thanks for the reply.
Probably should've posted a bit more of my code, as I am using the URL identifier.
Code: Select all
put "ftp://" & gUser & ":" & gPWD & "@" & gLocation into extFTPURL
put url (extFTPURL) into tConnect
if the result is not empty then
-- we can't connect and do whatever we need doing
else
-- we do what we need to upload the images here
end if
The reason I first put the ftp:// into extFTPURL is so I have a base URL that I can later add on the files I need to upload as in:
Code: Select all
put extFTPURL & tFileToCopy into fullFTPPath
.
As said, the whole ftp'ing works fine as long as my settings are ok.
Checking the result for "error" doesn't seem to work, and have to use "empty". That way I do get errors -as expected- when the username or password is incorrect, but when the pathname to the ftp folder is correct or not, that always seems to throw an error.
I'm probably doing something wrong but haven't been able to figure it out, as it's just the checking for the folder existence that goes wrong. How would I get back a folder listing?
Many thanks,
Bert
Re: FTP access
Posted: Thu Nov 07, 2013 8:59 pm
by jacque
What errors do you get? And what is the format of the path in gLocation?
If the url ends with a slash, indicating a folder, it should return a list of files inside that folder. I'm not sure, but it may only work with http, not with ftp, and your server has to be set up to show file lists as the default if there is no index page. Mine is set up to forbid file listings, so I can't use this trick. The only reason I mentioned getting a file listing is because that's what is returned automatically if you get a url for a folder -- provided the server allows it. If you get a file listing back, then you know the folder exists.
Here's another way to get a listing:
http://runtime-revolution.278305.n4.nab ... 47491.html. I haven't tried it.
Re: FTP access
Posted: Thu Nov 07, 2013 9:26 pm
by bertBUSIbr8
Hi Jacque,
Thanks for your time.
The only error I'm getting is:
java.io.IOException: Unable to connect to server: Unable to retrieve file: 550
when checking the result.
the format of the path is: 192.186.1.6/Documents/Scanner/
the result is the above error and checking tConnect will give an empty one, so doesn't look like anything's returned.
Indeed, if I would get back a list of files even if empty, that'd be ok and indicate the folder is there. But the folder being there or not doesn't matter, I always get the error.
As soon as I check for a file, works perfect. But I can't rely on a file in case someone decides to clear out the folder on the FTP. I will have no control over that.
Thanks for the link but the libURLSetFTPListCommand only works for desktop apps, and even just trying it makes the Android app hang.
Will have another think about it.
Reagrds,
Bert
Re: FTP access
Posted: Fri Nov 08, 2013 1:12 am
by jacque
Oops, sorry, I didn't even notice we were in the Android section here. (I've done that before.) Mobile has a more limited set of network commands, and libURL isn't supported -- which you found out the hard way. Sorry to make work for you. I'm out of answers I'm afraid, I haven't done any more than fetch web pages on Android.
Re: FTP access
Posted: Fri Nov 08, 2013 2:28 am
by Simon
Hi Bert,
You could do a file listing first using php (google php script for folder listing). Once you have that then do your ftp stuff.
Simon
Re: FTP access
Posted: Fri Nov 08, 2013 3:39 am
by FourthWorld
Another option might be to use POST over HTTP. That would require having a CGI on the server that can handle the incoming data, but there are several file upload examples for PHP and probably some for LiveCode Server that shouldn't be hard to turn up.
Another advantage with HTTP is that you can put an SSL certificate on the server for encrypted streams, while FTP sends the login credentials in plain text, an exposure for man-in-the-middle attacks.
Re: FTP access
Posted: Fri Nov 08, 2013 10:36 am
by bertBUSIbr8
Hi,
Thanks for the suggestions, but I don't think php and cgi are solutions I can use.
Originally this was to work over smb, but since that doesn't, the end client will have to run a ftp server locally [synching of the files only needs to happen when the employees are on the local network, not over the internet from anywhere].
If only I can find a way to check the validity of the pathname, I'm sorted. Everything else works as planned. If my password or username are wrong, that's intercepted and handled, but it's the pathname that's bugging me.
Thanks again.
Bert
Re: FTP access
Posted: Fri Nov 08, 2013 4:46 pm
by bertBUSIbr8
Thought I tried something different:
Code: Select all
local extFTPURL
on mouseUp
put "" into fld "info"
put ("ftp://user:pwd:@192.168.1.6/Documents/Scanners/" ) into extFTPURL
load URL extFTPURL with message "finishedDL"
end mouseUp
on finishedDL
put "finished" & RETURN & URL(extFTPURL) into fld "info"
end finishedDL
And whilst that works on the desktop, no problem, I get a file listing, confirming the folder, that returns empty on Android.
Even when I give it a non-existing folder on the ftp, no error, just empty.
Clearly something that's not working on Android then.
Bert