HomeProductsFTPShell ClientFTPShell Script › Script 2
#*************************************************************
#
#  Name: multiupload.fscr
#
#  Desc: Upload a file to multiple servers. Connect to each server,
#        upload the file and disconnect.
#        NOTE: For debugging, be sure to enable the log
#              file for the session used to schedule
#              this script.
#        NOTE: Always verify that a script is doing
#              exactly what you wanted it to do,
#              before scheduling it as an automated
#              task to avoid unpleasant surprises!
#*************************************************************


# Try to connect to the FTP server - 3 attempts max.
# If the connection was successful, exit out of the loop early.
# Otherwise, wait for 10 seconds and try again until the loop
# is exceeded (3 in our case)
# NOTE: Whenever a macro that starts with "ftp" is executed,
#       eg. ftpconnect, ftpsetpath, etc., the result of
#       the last executed macro is stored in the keyword
#       "ftpresult"

loop 3 begin
  ftpconnect("ftp.ftpserver1.com", 21, "anonymous", "anon.com");
  if(success eq ftpresult) begin
    exitloop;
  end else begin
    waitsecs(10);
  end
end


# Check if the ftpconnect command was successful.
# If the connect was not successful, print out an error
# message and end the script.
# NOTE: loop, if, and foreach statements must contain
#       enclosing "begin" and "end" blocks.

if(success ne ftpresult) begin
  print("ERROR: could not connect to server after 3 attempts");
  endscript;
end


# Set the desired local and remote paths
# NOTE: "local" and "remote" are keywords used to denote the local
#       and remote computers respectively.
# NOTE: Since "\" is also used as an escape character to specify
#       printable quotes, local paths may be specified using a
#       double backslash like "c:\\myfolder"

ftpsetpath(local, "c:\\temp");

if(success ne ftpresult) begin
  print("ERROR: could not set local path");
  ftpdisconnect();
  endscript;
end

ftpsetpath(remote, "/");

if(success ne ftpresult) begin
  print("ERROR: could not set remote path");
  ftpdisconnect();
  endscript;
end


# If passive mode transfers are required, enable passive mode

enablepasv();


# Set the transfer type to auto. Valid keywords are "ascii",
# "binary" and "auto".
# Also, set the rules to use if a duplicate file already exists
# in the destination path. The files may be compared by size or
# by date. This is indicated by the keywords "bysize" or "bydate".
# The following rule keywords may be specified: "resume", "rename"
# "overwrite", and "skip". Refer the help manual for the syntax of
# the "setduperules" macro.

settransfertype(auto);
setduperules(bysize, overwrite, skip, skip);


#upload the file to the ftp server

ftpupload(file, "local_file.txt");

if(success ne ftpresult) begin
  print("ERROR: could not upload file");
  ftpdisconnect();
  endscript;
end


# Finally, disconnect from the remote ftp server

ftpdisconnect();


# Repeat the entire sequence again for the second ftp server

# Try to connect to the FTP server - 3 attempts max.
# If the connection was successful, exit out of the loop early.
# Otherwise, wait for 10 seconds and try again until the loop
# is exceeded (3 in our case)
# NOTE: Whenever a macro that starts with "ftp" is executed,
#       eg. ftpconnect, ftpsetpath, etc., the result of
#       the last executed macro is stored in the keyword
#       "ftpresult"

loop 3 begin
  ftpconnect("ftp.ftpserver2.com", 21, "anonymous", "anon.com");
  if(success eq ftpresult) begin
    exitloop;
  end else begin
    waitsecs(10);
  end
end


# Check if the ftpconnect command was successful.
# If the connect was not successful, print out an error
# message and end the script.
# NOTE: loop, if, and foreach statements must contain
#       enclosing "begin" and "end" blocks.

if(success ne ftpresult) begin
  print("ERROR: could not connect to server after 3 attempts");
  endscript;
end


# Set the desired local and remote paths
# NOTE: "local" and "remote" are keywords used to denote the local
#       and remote computers respectively.
# NOTE: Since "" is also used as an escape character to specify
#       printable quotes, local paths may be specified using a
#       double backslash like "c:\myfolder"

ftpsetpath(local, "c:\temp");

if(success ne ftpresult) begin
  print("ERROR: could not set local path");
  ftpdisconnect();
  endscript;
end

ftpsetpath(remote, "/");

if(success ne ftpresult) begin
  print("ERROR: could not set remote path");
  ftpdisconnect();
  endscript;
end


# If passive mode transfers are required, enable passive mode

enablepasv();


# Set the transfer type to auto. Valid keywords are "ascii",
# "binary" and "auto".
# Also, set the rules to use if a duplicate file already exists
# in the destination path. The files may be compared by size or
# by date. This is indicated by the keywords "bysize" or "bydate".
# The following rule keywords may be specified: "resume", "rename"
# "overwrite", and "skip". Refer the help manual for the syntax of
# the "setduperules" macro.

settransfertype(auto);
setduperules(bysize, overwrite, skip, skip);


#upload the file to the ftp server

ftpupload(file, "local_file.txt");

if(success ne ftpresult) begin
  print("ERROR: could not upload file");
  ftpdisconnect();
  endscript;
end


# Finally, disconnect from the remote ftp server

ftpdisconnect();


# we can now finish the script.

endscript;

Download Free 30 Day Trial

Download FTPShell Server and FTPShell Client software and try it out free for 30 days.

Go to the Download Page



Buy License

Purchase a license for FTPShell Server or FTPShell Client.

Find out more about Licensing Options



FTPShell Server

File Transfer Server Software that supports FTP and secure SFTP and FTPS protocols.

Find out more about FTPShell Server



FTPShell Client

File Transfer Client Software that connects to Servers supporting FTP, SFTP, and FTPS.

Find out more about FTPShell Client



Operating System Requirements

FTPShell Server and FTPShell Client work with all Microsoft Windows Desktop and Windows Server Operating Systems including Windows XP/7/8/10/11 and Windows Server 2003/2008/2012/2016/2019/2022