tcpcmd.upload
Uploading Files to FTP Servers

tcpcmd.upload is a one-line means to upload a file, a folder, or a list of files and folders to an FTP file server.

tcpcmd.upload can access anonymous and private FTP accounts.

Here is an example of tcpcmd.upload, using the fewest parameters:

tcpcmd.upload ("ftp.someServer.com", "Hard Disk:myFile.txt")

Here, we're saying, "Upload myFile.txt in the root directory of Hard Disk to ftp.someServer.com, storing it with the same name in the anonymous account's default directory."

That's saying quite a lot with just a simple Usertalk statement.

We can upload a whole folder of files:

tcpcmd.upload ("ftp.someServer.com", file.getSystemDisk () + "Desktop Folder:NewUploads:")

Since we're uploading a whole folder, the files will be placed in a directory on the host having the same name as the folder. If the directory doesn't exist, it will be created. Since we didn't specify a destination directory, the directory will be in the anonymous account's default directory.

We can specify the destination directory for the files:

tcpcmd.upload ("ftp.someServer.com", "Hard Disk:myFile.txt", "/newFiles/")

Here, we're asking the myFile.txt be placed in the directory newFiles, which is in the anonymous user's default directory.

Most of the time, FTP servers will require you to have a valid account before you can upload files to it. You will need to specify your username and password when you use tcpcmd.upload:

tcpcmd.upload ("ftp.someServer.com", "Hard Disk:myFile.txt", "/newFiles/", "myUserName", "mYpAsSwOrD")

If you leave out the destination directory, you'll need to name the parameters that follow (e.g. username:"myUserName").

The syntax of tcpcmd.upload is:

tcpcmd.upload (host, sourcePath [,destPath] [,username] [,password] [,replace] [,nested] [,transferAs] [,timeOut] [,port] [,iso8859] [,bufSize])

Where:

  • host

    a string containing the IP address or domain name of the server to upload to

    "ftp.someServer.com"

  • sourcePath

    a string containing the path to the file or folder you want to upload.

    "Hard Disk:Desktop Folder:myTextFile.txt"

  • destPath

    an optional string containing the path to the destination file or directory on the server. If a directory is specified, and it does not exist, it is created. If destPath is omitted, the file or folder is placed in the default directory of the account on the host being used.

    "/newFiles/"

  • username

    an optional string containing the username of the account you want to log on with. If omitted or blank, "anonymous" is used.

    "myUserName"

  • password

    an optional string containing the password for the account you want to log on with.

    "myPassword"

    If omitted or blank, and the username used was "anonymous" or username was omitted, then the value stored in Frontier's odb at user.mailaddress is used. This is typically set to your email address and it is often what anonymous FTP servers want you to use for password.

  • replace

    an optional boolean containing either true or false. If true, then any existing file or directory specified in the sourcePath that exists on the server will be deleted. If false (the default), then the file or folders will not be deleted. If you set replace to false and the file or directory already exists, an error will occur and the file/folder(s) will not be uploaded.

    replace:true

  • nested

    an optional boolean containing either true or false. If true (the default), than all files in all sub-folders in the source path are uploaded.

    nested:true

  • transferAs

    an optional character or one-character string containing one of the following values:

    • "A" - ASCII - the file is transferred as an ascii text file.
    • "I" - bInary - the file is transferred as binary. The contents of the file will be stored in the data fork.
    • "M" - Macbinary - the file is to be transferred in MacBinary mode, if the host supports it. NOTE: MacBinary transfers are not supported in this version of tcpcmd.
    If transferAs is omitted or nil (the default), tcpcmd will use "smart" transfer mode selection. If Internet Config is present on the system, tcpcmd will use the filemappings defined in IC to determine the transfer method. If IC is not present, tcpcmd will upload files whose name end with ".htm", ".html", ".txt", ".asc", ".hqx", ".uu", and ".uue" as text. If IC is not present, and the file does not end with a suffix as shown above, it is uploaded as binary.
  • timeout an optional number containing the number of seconds upload will wait at each step in the sending and receiving process before it gives up and returns to the caller. The default timeout used is defined in tcpcmd.timeouts.ftp.

  • port an optional number for the port to use to make the ftp connection. The default is defined in tcpcmd.ports.ftp (port 21). This parameter is necessary if your ftp server uses a port other than the usual ftp port.
    port:2222

  • iso8859

    an optional boolean containing either true or false. If false (the default), then no translation of the file is performed during upload. If true, the file is assumed to be in ISO-8859-1 format and will be converted from the Macintosh character set equivalents during the upload.

    iso8859:true

  • bufSize

    an optional number specifying the size of the buffer Frontier should use when downoading a file. The default value is 5120 bytes. Please note that this version of tcpcmd will use up to twice the amount specified in bufSize since it must use some Frontier string verbs.

Restrictions

tcpcmd.upload does not yet support Macbinary transfers.


This page was last built on 8/1/98; 10:28:46 PM ET by Alan German, asg@erols.com. At the moment, I am using Macintosh OS to work on this website. The "Electric Cactus" graphic is based on original artwork owned by UserLand Software and is used with their permission.