Script

FTP

The professional tool to automate FTP, SFTP, FTPS and Batch FTP

Syntax:

PUTFILE(file,SUBDIRS)

  • file: individual file name or wildcard expression for multiple files. This parameter may include both absolute and relative paths, for example “C:\htdocs\*.gif or “htdocs\*.gif”
  • SUBDIRS (optional): Upload subdirectories. If this parameter is supplied PUTFILE will upload entire directory trees.

Remarks:

  • This command will overwrite remote files as needed.
  • The wildcards supported are “*” and “?”. If you are not familiar with the wildcard “?” see the example below.
  • The file parameter is case insensitive.
  • Use CHDIR to set the remote working directory before calling PUTFILE. Files will be uploaded to that directory.
  • Use SETPASSIVE to disable passive transfer mode if you encounter firewall problems.
  • Use SETTYPE to change the data transfer type. Default is Binary (most common).
  • Use SYNC instead of PUTFILE to upload new or modified files only.
  • Use a combination of GETLIST and FOREACH if you want to handle a set of files separately.

Return value:

PUTFILE will return “OK” if every file has been uploaded successfully. If the operation fails it will return an error code. You may retrieve the return value and execute various operations depending on this value. See Error Handling.

See also:

SETPASSIVE
SETTYPE
GETFILE
SYNC

Example:

# Connect to ftp.myftp.com
OPENHOST("ftp.myftp.com","myuser","mypassword")
 
# Upload C:\htdocs\mydir\PriceList.xls
# to the remote directory /excel_docs
CHDIR("/excel_docs")
PUTFILE("C:\htdocs\mydir\PriceList.xls")
 
# Upload all files in C:\htdocs\help\images
# to the remote directory /help/images
CHDIR("/help/images")
PUTFILE("C:\htdocs\help\images\*.*")
 
# Upload all files and directories in
# C:\htdocs\stuff to the remote directory /stuff
CHDIR("/stuff")
PUTFILE("C:\htdocs\stuff\*.*",SUBDIRS)
 
# Upload all zip files with a file name starting with "backup-" followed
# by two arbitrary characters and ending with "-old". For example,
# backup-54-old.zip
PUTFILE("backup-??-old.zip")
 
CLOSEHOST