Tip on LibURLFtpUploadFile "callback"

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Tip on LibURLFtpUploadFile "callback"

Post by doobox » Mon Jul 11, 2011 9:34 am

Hi there,

I am looking for a tip really, on handling the callback from LibURLFtpUploadFile.

Ok so i have the callback named "uploaddone".
All works great with this handler for a single upload.
But this handler is checking if the file has been uploaded. If it exists it is all good.

My problem is i will be overwriting the file, many times, and want to use the same handler each time.
So this is going to think its all good, even if a subsequent upload fails, as the file already exists from the first upload.

Code: Select all

on uploaddone
   if not (there is a file tFilePathOnServer) then
      set the visible of field "error" to true
   else
      set the visible of field "done" to true
   end if
end uploaddone
Can anyone offer a tip to check the file's time stamp, or something the like...?
Kind Regards
Gary

https://www.doobox.co.uk

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Tip on LibURLFtpUploadFile "callback"

Post by SparkOut » Mon Jul 11, 2011 10:29 am

Instead of overwriting the file that is there, delete it (or better yet, rename it first, so there is always a backup) before uploading the new file. If you can access the file location with Livecode's built-in commands (as suggested by your use of "if there is a file"), you can set the directory to the location required and use "the detailed files" to get comprehensive file info. Otherwise you could maybe use libURLftpCommand with a DIR command (MS ftp command line client returns detailed file information for the whole directory), or maybe if not implemented, you could try a SIZE request to get the filesize of the new upload.

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Tip on LibURLFtpUploadFile "callback"

Post by doobox » Mon Jul 11, 2011 11:13 am

Thanks, there are a good few options there.

If i start using the libURLftpCommand. How do i tell the command which file to delete, rename, size etc...
I tried pointing directly at:

Code: Select all

get libURLftpCommand("DELETE","doobox.co.uk/public_html/thefile.txt:21","username","password")
With no effect.

it seems from the docs you only enter your root into the commend.

Code: Select all

get libURLftpCommand("DELETE","doobox.co.uk:21","username","password")
So how can i target a file at a know location with this command..?
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Tip on LibURLFtpUploadFile "callback"

Post by doobox » Mon Jul 11, 2011 11:21 am

Do you build a complete set of commands on the ftp command line, something like:

Code: Select all

get libURLftpCommand("CD","thefoldername","DELETE","thefile.txt","doobox.co.uk:21","username","password")
if so what is the correct syntax..?
Kind Regards
Gary

https://www.doobox.co.uk

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Re: Tip on LibURLFtpUploadFile "callback"

Post by SparkOut » Mon Jul 11, 2011 4:01 pm

Ah, I see you cannot use the same syntax you find in command line ftp client programs. You need to use the raw ftp commands, a list can be found on http://en.wikipedia.org/wiki/File_Transfer_Protocol
or here http://www.nsftools.com/tips/RawFTP.htm which gives more information about how to use each raw command.

The syntax will be "command" (which is the whole command that you would normally type on the ftp client command line),"host","username","password" in each case so your line should look like:

Code: Select all

get libURLftpCommand("DELE /public_html/thefile.txt","ftp.doobox.co.uk","username","password")
assuming ftp.doobox.co.uk is the alias for your ftp connection IP. Port 21 will be used by default.

You could try renaming the file with the RNFR and RNTO commands.

Code: Select all

get libURLftpCommand("RNFR /public_html/thefile.txt","ftp.doobox.co.uk","username","password")
-- you should get a response code/string beginning with 350 for a successful seek of the file to be renamed
if it begins with "350" then
  -- apply the new name to the file referenced in the RNFR command
  get libURLftpCommand("RNTO /public_html/thefile.bkp","ftp.doobox.co.uk","username","password")
else
  answer "the file to be renamed was not found"
end if

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Tip on LibURLFtpUploadFile "callback"

Post by doobox » Mon Jul 11, 2011 4:20 pm

Sweet...1 that will keep me busy a while :-)
Kind Regards
Gary

https://www.doobox.co.uk

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: Tip on LibURLFtpUploadFile "callback"

Post by doobox » Mon Jul 18, 2011 2:36 pm

Hi there,

Not quit as straight forward as i thought "my workaround"

On a button i have this hacky way of uploading a folder to the server. As you cant upload a file to a folder that does not already exist in one operation with ios.
this hack will not return anything but error in the urlProgress even though it does indeed create a folder.

Code: Select all

   put"ftp://"&gUsername&":"& URLEncode(gPassword) & "@"&gServer&"/"&gPath&"/Airweaver/" into tURL
   put "rubish" into URL tURL -- this works on it's own and does create a folder "Airweaver"
end touchEnd


on urlProgress pURL, pStatus
   if pStatus is "error" then
     testfileupload --goes to the handler on the card
   end if
end urlProgress
So i figured i could then quickly upload a test file to the newly created folder, to acctually get a true return from urlProgress
The next handler on the card to upload a test file to the newly created folder and test if the test file has been uploaded:

Code: Select all

on testfileupload
   put"ftp://"&gUsername&"t:"& URLEncode(gPassword) & "@"&gServer&"/"&gPath&"/Airweaver/auth.txt" into tURL
   put "authenticated" into URL tURL
end testfileupload

on urlProgress pURL, pStatus
   if pStatus is "uploaded" then
      put "uploaded" & cr into field "result"
   end if
   if pStatus is "error" then
      put "error" & cr into field "result"
   end if
end urlProgress
This still returns an error every time, when the operation is chained like this.
I was under the impression that urlProgress would be returned to the object that it is called from.
It looks to me like i am calling it from the card in the second handler after the Airweaver folder has been created, so there should not be a problem with that second ftp upload..?

[EDIT] i did check the server after each of my tests, and the folder does get created but the test file does not, when chained like this.

Can anyone see the error of my ways here..?
Kind Regards
Gary

https://www.doobox.co.uk

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

A need little help with "on urlProgress" please

Post by FireWorx » Sun Sep 25, 2011 6:04 am

Hi, I am struggling a little bit with the "on urlProgress pUrl, pStatus, pMessage" Below is my code snippet that loads the PDF. I would like to check to see if the Url load happened and if not take some action. Based on the code snippet below what am I doing wrong. I still have trouble with parameters. Your help very much appreciated.
Dave

put "file:///" & specialfolderpath("documents") & "/" & tFolderNprefix & tMapSuffix & ".pdf" into tLocalPDF
replace " " with "%20" in tLocalPDF
iphoneControlSet sBrowserId, "rect" , the rect of group "Browser"
   iphoneControlSet sBrowserId, "visible" , "true"
   iphoneControlSet sBrowserId, "autoFit", "true"
   iphoneControlSet sBrowserId, "url", tLocalPDF
urlProgress tLocalPDF
end mouseUp
on urlProgress pUrl, pStatus, pMessage
if pStatus is "error" then
answer "Encountered Error:" && pMessage with "Okay"
end if
end urlProgress

Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Tip on LibURLFtpUploadFile "callback"

Post by Klaus » Sun Sep 25, 2011 12:21 pm

Hi Dave,

1. you do not LOAD anything in your handler, so your script does not make sense!
Your handler will only receive a "urlProgress" message after you do a "load url ..."
and not after setting the URL for a browser!

Check for "Non-file URL access" in the "iOS Release notes": Menu -> Help!

2. you are loading a LOCAL (sic!) PDF file, which should be displayed almost instantaniously,
so no need for a message anyway :D


Best

Klaus

FireWorx
Posts: 362
Joined: Wed Sep 07, 2011 9:39 pm

Re: Tip on LibURLFtpUploadFile "callback"

Post by FireWorx » Sun Sep 25, 2011 11:38 pm

Hi Klaus,
What I ended up doing is use a script to see if the file existed and if it didn't then stop the process and display an error message. I am using a grid system to navigate 8 different ways through a bunch of map PDF's and when I get to the edge of the district boundary and run out of maps I need to catch the failure to "display" not "load" the url in the browser. Thanks for the assist on the difference. I will check that section in the IOS release notes.
Thanks once again,
Dave

Post Reply