﻿Copy files via FTP (FtpCopy and FtpRefresh)
===========================================

"FtpCopy" and "FtpRefresh" are programs to copy file to an FTP server. They are very
useful for recurring operations like copying files to a web server for update.

With "FtpCopy" you can configure different copy tasks under free selectable names. 
The copy process can be started interactively using the Windows user interface or
by using the command line options. The latter will allow embedding into a batch 
file or a Desktop shortcut.  

The console program "FtpRefresh" is particularly designed for using in batch 
scripts, (see below).

Configuring a task:
-------------------
To create a task, click the button at the upper right and enter a unique name.
Then, select the source directory providing the file to be copied.
There are two options to select the files which also can be used in combination:
1. direct selection of one or several files
2. specifying a file filter like *.zip

In addition, you can specify one or several comma separated filter expressions
to exclude matching filenames, for example "~*.html".

Clicking the button at the right of the FTP target directory field , will open a 
dialog to enter the specification required for FTP transfer, as there are server, 
port, remote directory, username, password an so on.

If only one file was selected for copying, you can apply an optional automatical
renaming.

In addition, you can specify if all or only older files should 
be overwritten or if only files not existing on the FTP server should be copied.

Notes on secure FTP connection:
-------------------------------
If a secure connection (FTPS) is used for data transfer, you must assign
appropriate certificates to the application. This will be done by customizing
the file "certfiles.cfg" which is loaded on program start. The specified files
must be located in the installation directory of the program.

Example for "certfiles.cfg":
[certificate]
RootCertFile = root.pem
CertFile     = cert.crt
KeyFile      = key.key
SSLPassword  = password

The required certificate files can be created using OpenSSL. First, create a
appropriate text file "cert.cnf" containing the requires preferences, see the
OpenSSL documentation for more details:  
https://www.openssl.org/docs/manmaster/man5/config.html

Configuration file template:
https://github.com/openssl/openssl/blob/master/apps/openssl.cnf

Example for a suitable batch file:
openssl genrsa -des3 -out root.pem 1024
openssl req -config cert.cnf -new -out cert.csr
openssl rsa -in root.pem -out key.key
openssl x509 -in cert.csr -out cert.crt -req -signkey key.key -days 730

Saving the configuration:
-------------------------
All settings are saved in the file "FtpCopy.ini" located in the 
"User's Application Data". Passwords will be stored encrypted 

Creating a Desktop shortcut
---------------------------
Clicking the button at the lower middle will create a Desktop shortcut to
the selected task. A double-click on the Desktop icon will immediately start 
the copy task using the specified settings.


Command line options for FtpCopy:
---------------------------------
To run the program from a batch file (or the command "Execute" in the Windows
start menu) you can use the following command line options:
Program call: FtpCopy <task> [options]
  <task> - Name of copy task (see above)
           If the name contains spaces, it must be enclosed by quotation marks.
  options  - If no options are specified, the program will open with its desktop
              window and show the settings of the specified task  
    /force  - The specified task will be executed immediately
    /continue - The status window will automatically be closed after file transfer 
    /ini:<name> - Use a different ini file to load the tasks (see above)
Note: "FtpCopy" is a GUI application showing the copy progress in a popup window


Command line options for FtpRefresh:
------------------------------------
"FtpRefresh" is a console program that loads the settings made in "FtpCopy" 
(ini file) and starts the copy process as specified. The copy progress is output
to the console window. So it is particularly suitable for using in batch scripts. 
You can specify more than one task in a line. The following options are available:

Program call: FtpRefresh <task1> <task2> ... [options]
  <task#> - Name of the copy tas (see above)
            If the name contains spaces, it must be enclosed by quotation marks.
    /ini:<name> - Use a different ini file to load the tasks (see above)
    /log        - Write the FTP communication log to a file (useful for debugging)
                  Example: /log:%TEMP%\FtpRefresh.log

After termination, the program returns an error code (exit code) to the calling 
application. This can be queried in a batch file via the variable ErrorLevel: 
  = 0 : Several files were copied
  = 1 : No files were copied

File mode:   FtpRefresh /file  <task> <file1> <file2> ... [options]
First, all file specified in the task will be copied. Then, the other specified 
files (<file1> <file2> ...) will be copied to the same FTP destination.  
              
J. Rathlev, September 2022            
