FtpsTransfer - Application For Secure Site Files & Database Transfer
v.1.2.7.0
Copyright (c) 2017-2024 by www.dennisbabkin.com. All rights reserved.
(Windows XP/Vista/7/8/8.1/10/11)
Requires: Microsoft .NET Framework 4.8

LAST MODIFIED: Oct. 2, 2024




DESCRIPTION:
================
Command line utility that allows to trasfer website files in one call using 
secure & encrypted SFTP or FTP(s) connections. It also allows to download a full copy
of the server database data exported into a file.

The tool supports saving & restoring of Unix/Linux file names on a Windows platform. 
For example: case sensitive file & directory names, as well as file names with characters 
that will be special, or illegal in Windows.

Additionally the tool supports using scrambled authentication password, so that it is not
exposed in a batch file or in a command line call.



Usage:
================

FtpsTransfer op [d|u|ua|ddb] host "HostName" usr "UserName" pwd "Password"
             dir "LocalPath" [srvdir "ServerDirectory"] [port "PortNumber"]
             [sftp|ftps|ftp] [sshKFP "key"] [setPerm|noPerm]
             [nested|noNested] [safeNm] [wait]
             [mysql dbh "DatabaseHost" dbnm "DatabaseName" dbusr "DatabaseUser"
                    dbpwd "DatabasePassword" dbfile "DatabaseFileName"]

where:

op        Operation type:
           d =  download directory from the server.
                 INFO: This tool downloads only files and directories.
                 INFO: Each downloaded directory will have the following files added to
                       it automatically. These files will be later used by the 'u' option
                       for uploading to the server:

                        = __FtpsTransfer_app_dirLst__
                            - will contain directory listing as it was received from server.

                        = __FtpsTransfer_app_nameAssoc__
                            - will contain associations between filenames on the server &
                              filenames used to store them in Windows. This file will also
                              contain permissions that files had on the server. If you add
                              or remove any files from the folder that you later wish to
                              include in the upload, make sure to edit this file as well.

           u =  upload directory (previously downloaded with "d" option) to the server.
                 INFO: This option should be used only to restore or move a previously 
                       downloaded directory, as it will only upload files & directories
                       that were originally downloaded with the "d" option.
                 INFO: This tool uploads only files and directories.

           ua = upload any directory to the server.
                 INFO: This option should not be used to upload directories that were
                       previously downloaded with the "d" option, as this will also
                       upload auxiliary files that are used by the "d" and "u" options.
                 INFO: This option does not set permissions on uploaded files & directories.
                 INFO: This tool uploads only files and directories.

          ddb = download a full copy of the server database data exported into a file.
                 INFO: The following parameters are also used with this option:

                        host, usr, pwd,       = used for secure SSH connection to the server
                        sshKFP                  to download the exported database file.

                        mysql, srvdir, port,  = used to connect to the database on the
                        dbh, dbnm, dbusr,       server and to export its data into a file.
                        dbpwd, dbfile

                        (Read below for details for each parameter.)

                 INFO: Note that uploading and importing of the database file is not 
                       supported due to security concerns. To import a MySql file, upload it
                       to the server first and then execute the following Shell command
                       to import it:
                       (You will be prompted to provide a database connection password.)

                       mysql -h "db.hostname" -u "dbUsr" -p "dbName" < "path-to/import_file.sql"

host      Host name (or IP address) of the server.
           INFO: Do not use the port number, or the protocol here.

usr       User name for authentication to the server.

pwd       Password for authentication to the server.
           INFO: You can specify either a plaintext password, an empty password as "",
                 or scrambled password in format xpd:'*', where * is the scrambled part.
           INFO: If you specify a plaintext password, due to the rules imposed on the 
                 Windows command line parameters, some characters in a plaintext password
                 may be misinterpretted or dropped by the Windows command line interpreter.
                 Thus it is recommended to always scramble your plaintext passwords to avoid
                 any ambiguities.
           INFO: To scramble a plaintext password, use the ScramblePwd tool:
                  https://dennisbabkin.com/utilities/#ScramblePwd
           INFO: Scrambled passwords can be used only on the same computer & by the same
                 Windows User account that the ScramblePwd tool was run under to generate
                 them. Such restriction was introduced by default.
           IMPORTANT: Although scrambling a password hides it from view, keep in mind
                      that it will be still possible to reverse-engineer the original
                      plaintext password from a scrambled one!

dir       Directory path on the local computer.
           INFO: For uploading a directory, this path must point to an existing folder.
           INFO: For downloading a directory, the folder will be created by the tool.
           INFO: When downloading a directory, all existing files in provided folder
                 will be overwritten without a prompt!
           INFO: The following special meta words can be used in the local folder path.
                 Each of them will be replaced with a corresponding value:

                 Meta Word   Substituted for
                 ---------   ------------------------------------------
                 #DT#        local date in local date format
                 #TM#        local time in local time format
                 #Y#         4-digit year (local time)
                 #M#         2-digit month (local time)
                 #D#         2-digit day (local time)
                 #h#         2-digit hour in 24-hour format (local time)
                 #m#         2-digit minute (local time)
                 #s#         2-digit second (local time)
                 #UDT#       UTC date
                 #UTM#       UTC time
                 #UY#        4-digit year (UTC)
                 #UM#        2-digit month (UTC)
                 #UD#        2-digit day (UTC)
                 #Uh#        2-digit hour in 24-hour format (UTC)
                 #Um#        2-digit minute (UTC)
                 #Us#        2-digit second (UTC)
                 #WUSER#     Local Windows user name
                 #COMP#      Local computer name
                 #HOST#      Host name of the server
                 #SUSR#      User name on the server used for connection to it

           INFO: Additionally any of the Windows environment variables can be used.

           EXAMPLE: The following path:
                     "%UserProfile%\Desktop\ftp #UDT#"
                    will be substituted with something similar to:
                     "C:\Users\John\Desktop\ftp 2017-10-12"

srvdir    [Optional] Directory on the server to download/upload to.
           INFO: Path on the server to download, or upload, a directory to/from.
                 This path is relative to the authenticated user's root directory.
           INFO: In case "op ddb" is used, this parameter may be used to specify
                 directory to place temporary exported database file. The name of the
                 exported file is picked as a scrambled hash value based on the local 
                 computer name where this tool is running.
                 If this parameter is not specified, this tool will place temporary 
                 export of the database file into the root directory on the server.
                 Note that this tool will remove such file upon completion.
           INFO: If omitted, the tool will use the authenticated user's root directory
                 on the FTP server.
           INFO: This path also supports special meta words described above for
                 the 'dir' parameter.

port      [Optional] Port number to use for connection to the server.
           INFO: If omitted, or set to 0, the tool will not provide any specific port
                 for the SSH/FTP(s) connection.

sftp      [Optional, Default] Specify for secure/encrypted SSH connection.
           INFO: When specified, the tool will use encrypted SFTP connection via the
                 SSH channel to communicate with the server.
           INFO: This option is used by default and can be omitted.

ftps      [Optional] Specify for a secure/encrypted FTP connection.
           INFO: When specified, the tool will use encrypted FTP connection to
                 communicate with the server.
           INFO: This connection does not support setting file & directory permissions
                 during uploading to the server.

ftp       [Optional] Specify for an older, insecure FTP connection. Not recommended!
           IMPORTANT: Using this option will make this tool communicate with the FTP
                      server in an open form, meaning that your password, as well as
                      any other data will be sent in the clear! This also means that
                      anyone can intercept and/or substitute the data in the process!
           IMPORTANT: Use this option only when the server does not support secure or
                      encrypted SFTP or FTPS connections!

sshKFP    [Optional] Used only with 'sftp' parameter, or it "op ddb" is used.
                     Specify the RSA MD5 key fingerprint that will be used to 
                     authenticate the server.
           INFO: Connection to the server will be allowed only if provided key
                 fingerprint matches the one provided by the server.
           INFO: Examples:
                (1) 1e:d1:5a:72:c4:8e:a3:ff:01:0a:3b:56:17:6f:e1:42
                (2) 1ed15a72c48ea3ff010a3b56176fe142

setPerm   [Optional, Default] Used only with 'sftp' parameter. Specify it to set 
          file and directory permissions when uploading.
           INFO: This option will have effect only when uploading a previously 
                 downloaded directory via 'op=d' option.
           INFO: This option is used by default and can be omitted.

noPerm    [Optional] Used only with 'sftp' parameter. Specify not to change file and
          directory permissions when uploading.
           INFO: In that case files and directories will retain their previous or
                 default permissions on the server.

nested    [Optional, Default] Specify to include any nested subdirectories.
           INFO: When specified, the tool will download, or upload, all directories
                 that are nested inside the provided directory.
           INFO: This option is used by default and can be omitted.

nonested  [Optional] Specify not to include nested subdirectories.
           INFO: When specified, the tool will not download, or upload, directories
                 that are nested inside the provide directory.

safeNm    [Optional] Specify to make filenames safe for Windows Explorer.
          INFO: Used only when downloading from the server.
          INFO: If specified, this tool will shorten filenames and replace all
                non-ASCII characters in them to make the resulting filenames in the
                downloaded directory compatible with the Windows Explorer, and namely
                be allowed to be ZIP'ed using means provided in Windows Explorer.

wait      [Optional] Specify to pause console window before closing it.
           INFO: This option can be useful to review the console output before it
                 automatically closes when the operation is finished.

mysql     [Optional] Defines database type as MySql. Must be used with "op ddb" only.

dbh       [Optional] Database host name or IP address for database connection.
           Must be used with "op ddb" only.
           INFO: Do not use the port number, or the protocol here.

dbnm      Database name to download. Must be used with "op ddb" only.

dbusr     Database user name for connection. Must be used with "op ddb" only.

dbpwd     Database password for connection. Must be used with "op ddb" only.
           INFO: You can specify either a plaintext password, an empty password as "",
                 or scrambled password in format xpd:'*', where * is the scrambled part.
           INFO: If you specify a plaintext password, due to the rules imposed on the 
                 Windows command line parameters, some characters in a plaintext password
                 may be misinterpretted or dropped by the Windows command line interpreter.
                 Thus it is recommended to always scramble your plaintext passwords to avoid
                 any ambiguities.
           INFO: To scramble a plaintext password, use the ScramblePwd tool:
                  https://dennisbabkin.com/utilities/#ScramblePwd
           INFO: Scrambled passwords can be used only on the same computer & by the same
                 Windows User account that the ScramblePwd tool was run under to generate
                 them. Such restriction was introduced by default.
           IMPORTANT: Although scrambling a password hides it from view, keep in mind
                      that it will be still possible to reverse-engineer the original
                      plaintext password from a scrambled one!

dbfile    Local database file path to download to. Must be used with "op ddb" only.
          INFO: File extension will be added automatically (".sql" for MySql)
          INFO: Note that if such file existed before this tool was called, it will be
                overwritten without any user prompts!
          INFO: You are allowed to use special meta words and Windows environment variables 
                described for the "dir" parameter above.

           EXAMPLE: The following file path:
                     "%UserProfile%\Desktop\db export #UDT#"
                    will be substituted with something similar to:
                     "C:\Users\John\Desktop\db export 2017-10-12.sql"


Return Codes:
================

   0  = if success downloading or uploading.
   -1 = if error(s) downloading or uploading.
         INFO: Check console output for error details.
   1  = if information window was shown only.
         INFO: This happens, for instance, when a help information is shown.





Examples:
===================================

1. Download "public_html" directory from the server & place it onto the local desktop
   into the "ftp" folder:

    INFO: The "ftp" folder will be created automatically by the tool.
    INFO: Note that we're downloading all nested directories (which is done by default.)
    INFO: We're using a secure/encrypted SFTP connection to the server via SSH channel
          (which is done by default.)
    INFO: The password in this example was scrambled using the ScramblePwd tool that you
          can download from the link below. Note that such scrambled password can be used
          only on the same computer, under the same Windows User account that was used to
          run the ScramblePwd tool.
           https://dennisbabkin.com/utilities/#ScramblePwd

   FtpsTransfer op "d" host "ftp.domain1.com" srvdir "public_html" dir "%UserProfile%\Desktop\ftp" usr "user123" pwd "xpd:'Xz8BAAAA0Iyd3wEV0RGMegDAT8KX6wEAAAB8+GG36Oe8T4VbbD55psYdBAAAAAIAAAAAABBmAAAAAQAAIAAAAG1JSqbgZvHUcYJtzfDSbLtSg4bF6CrQLTcxMhsj9x5fAAAAAA6AAAAAAgAAIAAAAOkx8f3gFH4Vw7ESCHP7B/oP3csxIWr0H+WLuqTbJUlEAAAAIOO1w5fALmEFJZf86m9+65AAAAA1jgf40hBwT6N5vFNWPFp566w2kbhKl8cF7A1S5Dv96t704L8molaOWtP1tmQvNl1ro/1swrsZY8ewlaqNwIYviaF'"


2. Upload previously downloaded folder to "public_html/backups" directory on the server,
   keep the console window on the screen when done. Use additional server authentication
   by requiring a match on its SSH fingerprint key:

    INFO: The "u" option assumes that the "ftp" folder on the desktop was previously
          downloaded using this tool with the "d" option. (See above for an example.)
    INFO: Note that we're uploading all nested directories (which is done by default.)
    INFO: You will need to obtain the SSH fingerprint key from the server itself.
    INFO: We're using a secure/encrypted SFTP connection to the server via SSH channel.
    INFO: The password in this example was scrambled using the ScramblePwd tool that you
          can download from the link below. Note that such scrambled password can be used
          only on the same computer, under the same Windows User account that was used to
          run the ScramblePwd tool.
           https://dennisbabkin.com/utilities/#ScramblePwd

   FtpsTransfer op u sftp host "ftp.domain2.com" usr "Admin" pwd xpd:'eFIBAAAA0Iyd3wEV0RGMegDAT8KX6wEAAAB8+GG36Oe8T4VbbD55psYdBAAAAAIAAAAAABBmAAAAAQAAIAAAAPA0ALIERBO60Wn5fEmd60hnsgbN1ctCyxg9JgHjfjRkAAAAAA6AAAAAAgAAIAAAANDKJOZOyZeCkiDcN5Cq+6LilX5S1KCP1CNzBzzD2EQ8EAAAAHL7SRWQKGmdHNFwMmUMviJAAAAA5zej1+BW20Z72zc/Icv/1c0V1FJE7d51Op521o/OVZmeFUOreWxeKzY8If9GXszOhQ/uJUqrkwBfJ6fVH/AQ5kVA' sshKFP "1e:d1:5a:72:c4:8e:a3:ff:01:0a:3b:56:17:6f:e1:42" dir "%UserProfile%\Desktop\ftp" srvdir "public_html/backups" wait


3. Download a single directory (without its nested subdirectories) from the server on
   the local intranet, using insecure FTP connection and a plaintext password:

    WARNING: It is HIGHLY NOT recommended to use insecure FTP connections!
             Specifying the "ftp" parameter will send your password, as well as the 
             files that are downloaded from the server in an open form, so anyone can
             see them! This also creates a risk of the "Man in the middle" attack, when
             someone can intercept and modify your files during the transfer!

    INFO: Note that in this case the password was also specified in the plaintext form
          in the "pwd" parameter. This exposes the password if the command line is
          saved in a batch file. Note that specifying a plaintext password in the "pwd"
          parameter does not influence how it's sent to the server. For instance, if
          you scramble your password, as was shown above, but still specify the "ftp"
          parameter, the tool will still send your password to the FTP server in a
          plaintext form!

   FtpsTransfer op d host "192.168.10.17" usr "joe123" pwd "GhP4D1fzU!xv7c8gIgK" dir "C:\Public\Shared\Joe's Files" srvdir "public/joe files" ftp nonested


4. Download full copy of MySql database from the server & place it on the desktop:

    INFO: First set of credentials is used for SFTP access, the second one for
          connection to the MySQL database. Both passwords are scrambled with the use
          of the ScramblePwd tool.
           https://dennisbabkin.com/utilities/#ScramblePwd

    INFO: For added security, the tool which check the server's SSH fingerprint to match
          the MD5 hash specified in the command line below.

    INFO: Downloaded database file will have "Year-Month-Date" attached to its name.
          It will automatically have .sql file extension added at the end.

   FtpsTransfer op "ddb" host "host.domain3.com" usr "admin" pwd xpd:'XzIBAAAA0Iyd3wEV0RGMegDAT8KX6wEAAAAit48vDR2LTqvQHqd2j+74BAAAAAIAAAAAABBmAAAAAQAAIAAAAHNqpDwH2aDMR+Qx7KLAJmoWfG96ucX9kKTa5Ru2THspAAAAAA6AAAAAAgAAIAAAAHoOdNUlKpwOUfYhKwQFJyHtlZ1JDtIvWOzYli8q7Sk4EAAAACw/t2funk6fM5/W4d6vX1RAAAAAeY7yLAPADZVdjPC2BwylnCuX9N41yJwg7tkswVwmW3UJUNsWxuycNTGFdo33aLij684q/PIDJ7Ixq+n9CqsSXfQi' sshKFP "1e:d1:5a:72:c4:8e:a3:ff:01:0a:3b:56:17:6f:e1:42" port 22 mysql dbh "mysql1.domain3.com" dbnm "database1" dbusr "dbUsr1" dbpwd xpd:'PVoBAAAA0Iyd3wEV0RGMegDAT8KX6wEAAAAit48vDR2LTqvQHqd2j+74BAAAAAIAAAAAABBmAAAAAQAAIAAAAKUGIn9OiRdJzS3FjZs+mJSlLMpIdW1tUiSdvSsZK9egAAAAAA6AAAAAAgAAIAAAAJMuNyMN8MOH0uMtpg6ATRUNEU5EWgPzaPHnhACaapPeEAAAACFHwiqpXYMs8Dlq3N1IRrpAAAAAW5QIQuCXxkmAer7Vi+idu4zHGBqMNA4DQb0wpUc0u2AIn2Cvn8PorHRumygCiIY9BzyDRDPqJH8AyItas4MS3+qT' dbfile "%UserProfile%\Desktop\db copy #Y#-#M#-#D#"





This tool was created using SSH.NET library:
https://github.com/sshnet/SSH.NET


To download Microsoft .NET Framework 4 go to:
https://www.microsoft.com/en-us/download/details.aspx?id=17718

To download your copy:
https://www.dennisbabkin.com/ftpstransfer

For feedback go to:
https://www.dennisbabkin.com/sfb/?what=info&name=FtpsTransfer


Thank you!















