FTP problem

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
pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

FTP problem

Post by pink » Wed Jul 02, 2014 8:40 pm

okay this is driving me crazy... the code below is supposed to upload the contents of a directory to an ftp site (specifically the CD drive)

the commented lines are to a directory on my Mac... on the Mac, this works as expected

on Windows the directory is the CD drive... when I run the program (and click the button that calls this handler) it seems to go through the motion and says it is uploading the files... but if I check on the site there are no files... I walked through it step by step and everything looked correct, but no files...

Code: Select all

on uploadAudio
     constant FTPHOST = "ftp.thiswouldbemysite.com"
     constant FTPUSER = "ausername"
     constant FTPPASS = "1234567890"
     --set the itemdelimiter to "/"
     --set the defaultfolder to "/Users/pink/Documents/qzqz"
     set the itemdelimiter to "\"
     set the defaultfolder to "D:\"
     put the files into tFileList
     repeat for each line zzz in  tFileList
          set the itemdelimiter to "\"
          put zzz into tFileForUpload
          put the last item of tFileForUpload into tFileName
          put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST&"/" &tFileName into tDestination
          libURLSetStatusCallback "UpdateStatus", the long ID of me
          libURLftpUploadFile tFileForUpload, tDestination, "uploadComplete"
     end repeat
end uploadAudio

on uploadComplete pURL, pStatus
     answer info pStatus
     if pStatus = "uploaded" then
          hide scrollbar "ProgressBar"
          answer "COMPLETE"
     end if
     if pStatus = "error" then
          hide scrollbar "ProgressBar"
          answer "ERROR"
     end if
end uploadComplete

on UpdateStatus pUrl, pStatus
   set the itemdel to "/"
   put last item of pUrl into tFileName
   set the itemdel to comma
   put empty into tStatusDisplayString
   --
   switch item 1 of pStatus
      -- Handle progress:
      case "uploading"
         put "Uploading" into tStatusDisplayString
      case "loading"
         -- Update progress bar:
         put item 2 of pStatus into tBytesReceived
         put item 3 of pStatus into tTotalBytes
         set the endvalue of scrollbar "progressbar"   to tTotalBytes
         set the thumbpos of scrollbar "progressbar" to tBytesReceived
         show scrollbar "progressbar"
         --
         if tStatusDisplayString is empty then 
            put "Downloading" into tStatusDisplayString
         end if
         put cr& tFileName &cr& tBytesReceived& " of "& tTotalBytes after tStatusDisplayString
         put  tStatusDisplayString into fld "statut2"
         break
         --
         -- Errors:
      case "error"
      case "timeout"
         answer pStatus
         exit to top
         break
         --
         -- Completed successfully:
      case "uploaded"
         --answer "Upload ok"
               hide scrollbar "progressbar"
      case "downloaded"
         hide scrollbar "progressbar"
         unload pUrl
         break
   end switch
end UpdateStatus
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: FTP problem

Post by Simon » Thu Jul 03, 2014 3:50 am

Hi pink,
Try this;

Code: Select all

put the last item of tFileForUpload into tFileName
put urlEncode(tFileName) into tFileName --add this line
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST&"/" &tFileName into tDestination
my guess is the are some weird filenames.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Re: FTP problem

Post by pink » Thu Jul 03, 2014 8:59 pm

unfortunately that didn't work

does it make a difference that the file name is mixed case?
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: FTP problem

Post by Simon » Thu Jul 03, 2014 9:38 pm

Maybe you could just try copying a file to the C: drive and ftp from there.
Just to test if it's the drive causing you the problem.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

pink
Posts: 280
Joined: Wed Mar 12, 2014 6:18 pm

Re: FTP problem

Post by pink » Sat Jul 05, 2014 4:06 pm

I've come to the conclusion that for whatever reason, the problem was my test file. After fiddling around with a few other options it did in fact work... I'm befuddled, but it is in deed working correctly
Greg (pink) Miller

MadPink, LLC
I'm Mad, Pink and Dangerous to Know

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

Re: FTP problem

Post by Klaus » Sat Jul 05, 2014 4:41 pm

Hi pink,

some general hints:
Livecode internally always uses the UNIX path delimiter SLASH -> /
So no need to do something like this:
...
set the itemdelimiter to "\"
set the defaultfolder to "D:\"
...
But rather this:
...
set the itemdelimiter to "/"
set the defaultfolder to "D:/"
...
Only use platform specific path delimiter when using SHELL!

You wrote:

Code: Select all

...
     put the files into tFileList
     repeat for each line zzz in  tFileList
          set the itemdelimiter to "\"
          put zzz into tFileForUpload
          put the last item of tFileForUpload into tFileName
          put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST&"/" &tFileName into tDestination
...
"the files" are just what it says: the "naked" FILENAMES WITHOUT any pathnames in fromt of them, so you only need this:

Code: Select all

...
     put the files into tFileList
     repeat for each line tFileName in tFileList
       ## Now tFileName already contains the correct filename
       put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST&"/" &tFileName into tDestination
...
Best

Klaus

Post Reply