How to use ftp commands ?

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
GoneToSail
Posts: 49
Joined: Sun Jan 24, 2010 10:34 pm

How to use ftp commands ?

Post by GoneToSail » Sat Aug 17, 2013 5:06 pm

Hi everybody !

I'm trying to read some file attributes (such as the modification date/time in seconds) of a file located on a remote server, and I assume I could do that using the libURLftpCommand function (but may be there is a simpler way...).
However I'm not familiar at all with the ftp commands, although I've tried to read the RFC 959 document, particularly section 4.1.3, as recommended in the LiveCode Dictionary.

My questions are:
1. What is the exact syntax of ftp commands to be sent in order to:
a) specify a directory on the remote server (CWD command ?),
b) obtain an information similar to "the detailed files" (LIST command ?)

2. Is there a way to retrieve this information only for one file by giving also its file name ?

Thanks for any assistance...

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

Re: How to use ftp commands ?

Post by Simon » Sat Aug 17, 2013 8:20 pm

Hey there sailor :)
In the dictionary look up just plain old ftp:
put "jim" into userName
put "jsmith@example.org" into userPassword
put "ftp://" & userName & ":" & URLEncode(userPassword) \
& "@ftp.example.com/title.txt" into fileURLToGet
get URL fileURLToGet

Here are some examples of valid ftp URLs:

ftp://ftp.example.org/directory/ -- list of files and folders in a directory
ftp://ftp.example.org/directory/file.exe -- a file on the server
ftp://user:password@ftp.example.org/myfile -- a file accessed by a password
ftp://ftp.example.com:3992/somefile -- using a nonstandard FTP port
From that it seems that if you specify a filename then it will download it not just show you it's attributes.

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

GoneToSail
Posts: 49
Joined: Sun Jan 24, 2010 10:34 pm

Re: How to use ftp commands ?

Post by GoneToSail » Sun Aug 18, 2013 8:41 am

Thank you very much Simon !
I appreciate finding an answer on returning from a nice sailing…
The "ftp URL ftp://ftp.example.org/directory/" syntax works fine, at least to get the file modification date.
The result is not as complete as what is obtained with "the detailed files" about local files, but it's perfect for the modification date, which was my initial goal.
Many thanks !

Post Reply