Page 1 of 1

file and ftp: where is the problem?

Posted: Fri Nov 22, 2013 7:21 pm
by alberto.fre
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

Re: file and ftp: where is the problem?

Posted: Fri Nov 22, 2013 10:58 pm
by Klaus
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

Re: file and ftp: where is the problem?

Posted: Sat Nov 23, 2013 9:43 am
by alberto.fre
:D :D
IT WORKS!!
thanks!
:D
Alberto

Re: file and ftp: where is the problem?

Posted: Sat Nov 23, 2013 1:35 pm
by Klaus
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

Re: file and ftp: where is the problem?

Posted: Sat Nov 23, 2013 3:17 pm
by alberto.fre
OK :)
Thanks