FTP2

Updated June 2019; see History

xcall FTP2, host, user, password, localpath, hostfile, hostdir, opcode, status port, {,emsg, privkey, passphrase }

(Windows and Linux; see History). FTP2.SBR provides the client side of FTP and SFTP file transfers. Similar to, and mostly upward compatible with the now deprecated FTPDLX, FTP2 offers additional features and support for the latest security patches and protocol updates.

Parameters

host  (String)  [in]

Specifies the name or IP address of the HOST computer you want to send files to or receive files from.

user  (String)  [in]

Specifies the user login name for the remote HOST. For anonymous FTP, use "anonymous"

password  (String)  [in]

Specifies the login password. For anonymous FTP, use your email address (e.g. myname@mydoman.com). Ignored when the privkey argument is specified.

localpath  (String)  [in]

Native file specification (Windows or Linux format, depending on the platform) for the local file (whether sending or receiving).  If no directory specified, the current login directory will be used. Note: you may want to use MX_FSPEC to translate an AMOS directory specification to a PC version. Otherwise, beware of case sensitivity under Linux. See Comments below for wildcarding.

The native file specification of the local file (to be sent or received), or of the directory listing to be created (see XFTPF_DIR). If not fully qualified, it will be treated as relative to the current local login directory. Note: you may want to use MX_FSPEC, or the function Fn'FQFS$() in SOSLIB:[907,10] to translate your filespec to native syntax; otherwise, beware of case sensitivity under Linux. See Comments below for wildcarding.

hostfile  (String)  [in]

May be the full pathspec of the remote file, or just the filename and extension. In the former case, leave hostdir blank, otherwise specify the directory in hostdir. hostfile is case sensitive. See Comments below for wildcarding and deletions.

hostdir  (String)  [in]

If not blank, it is prepended to the hostfile field to form the full pathspec of the remote file. hostdir is case sensitive.

opcode  (Num)  [in]

Note that while most of the codes apply to both FTPDLX and FTP2, some apply—as indicated—only to one or the other.

Symbol

Value

Description

XFTPF_GET

&h00000000

Transfer from server to client PC.

XFTPF_PUT

&h00000001

Transfer from client PC to server.

XFTPF_ASCII

&h00000002

ASCII transfer mode. Note that some FTP servers will ignore the ASCII option as a security precaution.

XFTPF_NOERRMSG

&h00000010

Suppress error dialogs.

XFTPF_PASSIVE

&h00000020

Passive transfer mode. This is often needed to get past firewall restrictions.

XFTPF_NOBANNER

&h00000040

Suppress the transfer banner.

XFTPF_SFTP

&h00000100

Use SFTP protocol instead of FTP. This requires a SSH2 service on the server side, typically at port 22.

XFTPF_VERSION2

&h00001000

Request FTP2. FTPSYNC mode only.

XFTPF_KEEPOPEN

&h00002000

Keep connection open. Automatically set for FTP2.

XFTPF_REUSE

&h00004000

Reuse previous connection if available. Automatically set for FTP2.

XFTPF_CLOSE

&h00008000

Close connection, no transfer.

XFTPF_RMVEXT

&h00000200

Rename host file after transfer, removing the last extension. This may be useful to prevent the file from being accessed by the remote system until the transfer is complete. Since it removes the last extension, you probably want to set the host file to have two extensions, such as myfile.dat.up. After the transfer is complete, the file would be renamed to myfile.dat.

XFTPF_DEL

&h00100000

Remote delete.

XFTPF_RECURSE

&h00200000

Recurse subdirectories, with wildcards.

XFTPF_DIR

&h00400000

Output directory listing of remote directory into localpath.

XFTPF_RENAME

&h00800000

rename a remote file or directory

The following are mutually exclusive (SFTP only); M=missing, N=newer, S=size.

XFTPF_SYNC_ALL

&h00000000

All matching files.

XFTPF_SYNC_M

&h01000000

All files that don't exist in destination.

XFTPF_SYNC_MN

&h02000000

All files that don't exist in destination, or are newer in source.

XFTPF_SYNC_N

&h03000000

Only files that exist in both places but are newer in source.

XFTPF_SYNC_MS

&h04000000

All files that don't exist in destination or are different size.

XFTPF_SYNC_MNS

&h05000000

All files that don't exist in destination or are different size or newer.

XFTPF_SYNC_DELM

&h0F000000

With XFTPF_DEL, only remote files not existing locally.

Definition file: ashell.def

 

status  (F,6)  [out]

Return status. Greater than zero indicates success. In some cases, primarily wildcard operations with SFTP protocol, status will return the number of files actually transferred or deleted. Negative values indicate errors as shown in the ASHNET Status Codes.

port  (Num)  [in]

Specifies the control port to use when connecting to the remote FTP/SFTP server. The most typical ports are 21 for FTP and 22 for SFTP, but servers are free to change them for various security and firewall-related reasons. In any case the parameter must be explicitly set.

emsg  (String)  [out]

Will contain a debug trace in the case of an error. Since this can be lengthy, you should provide a string of at least 1500 bytes to contain it all. In the case of wildcard transfers or deletions using the SFTP protocol, on success it will contain a list of the files actually transferred or deleted.

privkey  (String)  [in])

contains the filespec of private key file in OpenSSH format. If specified and non-blank, FTPDLX will use public/private key authentication rather than standard password authentication.

passphrase  (String)  [in]

is the passphrase for the private key. May be omitted if the private key is not passphrase-protected.

 

Comments

The source file specification—in localpath or hostfile, depending on the direction of the transfer—may contain the "*" wildcard. For example, /vm/miame/dsk0/007006/*.dat, or /vm/miame/dsk0/007006/ab*, or even c:\vm\miame\dsk0\007006\cyxz*.d*.

When receiving files using a wildcard hostfile specification, localpath should be set to the base directory to receive the files. Setting localpath to "" will result in them being received into the local root directory, which will likely fail due to permissions.

FTP2 is used in ZTXFER and ATSYNC if the /2 switch is specified.

The XFTPF_SYNC opcode options apply only to the SFTP protocol (XTFPF_SFTP), and only come into play when a wildcard is specified in the relevant source argument and the destination is just a directory. The wildcard source argument acts as the first level of filtering on files to be transferred, with further filtering determined by the XFTPF_SYNC_xxx options.

Note that unlike most of the XFTPF_xxx flags, which are coded as unique bits and thus could theoretically be combined in any way, provided it makes functional sense, the XFTPF_SYNC_xxx options are all mutually exclusive—i.e., choose only one. Also note that XFTPF_SYNC_DELM only applies in conjunction with XFTPF_DEL.

When doing wildcard transfers or remote deletions, the status parameter returns on success the number of files transferred or deleted, rather than just zero. Also, the emsg parameter in that case will contain a list of the files transferred or deleted, delimited by line breaks. See History notes below related to XFTPF_DEL.

See program FTPTST in SOSLIB:[907,33]

Debugging

In most cases, FTP2 will create a log file in the %TEMP%  (Windows) or /tmp (Linux) directories named ashnet.log which may contain useful details.

See Also

•     FTPDLX (deprecated)

History

2021 December, A-Shell 6.5.1709, ASHNET 1.14.177:  FTP2TIMEOUT environment variable now affects SFTP as well as FTP connections. Also, XFTPF_RMVEXT support added.

2021 June, A-Shell 6.5.1703, ASHNET 1.4.174:  XFTPF_DEL now supports a complete filespec in hostfile. Previously it required the directory and filename to be split into hostdir and hostfile.

2019 June, A-Shell 6.5.1662:  Add opcodes XFTPF_DIR and XFTPF_RENAME.

2017 February, A-Shell 6.3.1544:  FTP2.SBR now exposed to Linux via libashnet.so.1.9.157. Wildcards are now supported in the SFTP protocol; previously they were only supported for the FTP protocol. New opcode options added.

2015 April, A-Shell 6.1.1406:  Added FTP/SFTP remote delete.

2015 March, A-Shell 6.1.1405, ASHNET 1.7.147:  you can now override the default timeout for FTP2.SBR (60 seconds) by defining the environment variable FTP2TIMEOUT as the desired timeout in seconds, e.g. .SETENV FTP2TIMEOUT=10. Note that this is implemented entirely in ASHNET.

2014 February, A-Shell 6.1.1379:  Added routine to A-Shell