SaveFile

Internet
Aptilis 1

SaveFile(Url, Content[, UserName[, Password[, Mode]]])

This is the page that describes how to use SaveFile with URLs.
Savefile understands two types of Urls:
- file:// (normal files, check the File names topic)
- ftp:// to get a file from an FTP server

Apart from that SaveFile works on normal file names, but it's decribed in another page. SaveFile will simply create and open a file named FileName and write the content you specified into it. If an old file existed under the same name, it will be deleted.

Specifying a Url
Here is an ftp Url: "ftp://ftp.freeware-madness.org/pub/games/fry-em.zip"

You can use IP numbers and port numbers as well to override the default port for ftp:// (21), such as:
"ftp://ftp.freeware-madness.org:1040/pub/games/fry-em.zip" or:
"ftp://123.45.67.101:1040/pub/games/fry-em.zip"

When do I need to specify a username, password, and mode?
Those are needed when you access an FTP server. Indeed, FTP servers will not grant you access, unless you identify yourself. Fortunately, a lot of public servers allow you to login using the login 'anonymous' and your e-mail address as a password.
Here are the default values assigned to these parameters if you don't specify them:
UserName: "anonymous"
Password: "" (No password)
Mode: "binary"

The mode indicates how you want the file to be transfered. "Binary" indicates that you want the file to be transferred absolutely unchanged. "Ascii" asks the FTP server to try and be smart about how to store/send text files. As far as I am concerned I always use binary, and then use Replace to get the proper line separators.
That's "\n" under Unix, and "\r\n" under Windows. I start by removing all the "\r" and then replace all the "\n" by "\r\n" if I am aiming at a PC target.

Return Value:
Number of bytes written.
If the value is different from the length of the string you specified, then check the _errno variable for details.

Example:

saveFile("ftp://myserver.com/home/file.txt", "Hello world\n-----------", "my_unsername", "my_password", "binary")
Result:
The file myfile.txt which contains:
Hello world
-----------
has been sent to the FTP server.

See also loadfile (internet).