file and ftp: where is the 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
alberto.fre
Posts: 20
Joined: Sat Nov 16, 2013 12:12 pm

file and ftp: where is the problem?

Post by alberto.fre » Fri Nov 22, 2013 7:21 pm

Ciao
My code write a file in directory Documents.The file name is the variable tName that the user write in a initial card
The script log-in into server ftp but the file upload fails (status Update: connected; status update: error)
I don't know the reason. I think the error is in definition of file path or file name.
Thanks.

Code: Select all

on mouseUp 
      # Start by getting the file to upload
   # Put your FTP server address, your login and your password
   --
   global tName
    set the defaultFolder to specialFolderPath("Documents")  
    put "file:"& tName &".txt" into tPath
   put fld "score" into URL (tPath)

put tPath into tFileForUpload

 # Get the name of the file for upload?
local tFileName
set the itemdel to "/"
put the last item of tFileForUpload into tFileName

# Data for Communication with server
constant FTPHOST = "ftp.drivehq.com"
   constant FTPUSER = "XXXXX.XXX"
constant FTPPASS = "XXXXXXXXXXXXXX"

local tDestination
put "ftp://" & FTPUSER & ":" & FTPPASS & "@" & FTPHOST&"/" &tFileName into tDestination

libURLSetStatusCallback "uploadProgress", the long ID of me
libURLftpUploadFile tFileForUpload, tDestination, "uploadComplete"
end mouseUp

#progress of upload
on uploadComplete pURL, pStatus
put "Status Update:" && pStatus && return after field 1
end uploadComplete
on uploadProgress pURL, pStatus
put "Status Update:" && pStatus && return before field 1
end uploadProgress

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

Re: file and ftp: where is the problem?

Post by Klaus » Fri Nov 22, 2013 10:58 pm

Hi alberto,

I always work with ABSOLUTE pathanmes and do not mess with "the defaultfolder" :D

Anyway that is not the problem:
You still have "file:" in tFileForUpload, so this is not a valid filename!

Do this:

Code: Select all

...
put specialFolderPath("Documents") & tName &".txt" into tPath
put fld "score" into URL ("file:" & tPath)
put tPath into tFileForUpload
## No "file:" at the beginning!

## Save 2 lines, lazy moi  :) 
put tName & ".txt" into tFileName

constant FTPHOST = "ftp.drivehq.com"
constant FTPUSER = "XXXXX.XXX"
constant FTPPASS = "XXXXXXXXXXXXXX"
...
Best

Klaus

alberto.fre
Posts: 20
Joined: Sat Nov 16, 2013 12:12 pm

Re: file and ftp: where is the problem?

Post by alberto.fre » Sat Nov 23, 2013 9:43 am

:D :D
IT WORKS!!
thanks!
:D
Alberto

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

Re: file and ftp: where is the problem?

Post by Klaus » Sat Nov 23, 2013 1:35 pm

Hi Alberto,

in cases like these, a little:
...
answer tFileForUpload
## and/or other variables in question!
...
will often lead to an extremely helpful slap on the forehead! :D


Best

Klaus

alberto.fre
Posts: 20
Joined: Sat Nov 16, 2013 12:12 pm

Re: file and ftp: where is the problem?

Post by alberto.fre » Sat Nov 23, 2013 3:17 pm

OK :)
Thanks

Post Reply