ftp commands

Transferring Files using FTP

Sharing files is one of the fundamental motivations for networking computers. FTP (File Transfer Protocol) is a protocol for transferring files over a TCP/IP network. FTP is an effective way to share data between heterogeneous network hosts. CobolScript has commands that allow you to program FTP clients to transfer files to and from FTP servers.

Most computers on the Internet support FTP access. Before you can build a program that will access files on these FTP servers, however, you will need the following:

· The name of the system on the network that has the files you want to obtain, or on which you want to place files. In other words, you need to know the fully qualified domain name or IP address of the host that you want to transfer files from and to.

· A valid user name and password to use on the remote computer. Many remote computers will allow anonymous ftp, which allows you restricted FTP access by using the user name anonymous and your email address as the password.

FTP is extremely useful for transmitting data rapidly between sites that need to share information system data. Using FTP eliminates many usual considerations when transferring files. By using FTP:

· You won’t need to worry about requiring both hosts to use the same types of disks or tapes to transfer files;

· You won’t have to break up a file into several smaller files because the larger file won’t fit on a single disk or as an email attachment.

CobolScript programs that transfer files using FTP commands can be scheduled to run at regular time intervals. This is allows you to have unattended file transfers between hosts.

When you try to connect to a remote computer using FTP, you will need to supply a valid user name and password. The CobolScript command FTPCONNECT is the command you should use to login to an FTP server. Here’s an example:

MOVE `deskware.com` TO host_name.

MOVE `anonymous` TO user.

MOVE `interpreter@deskware.com` TO password.

FTPCONNECT USING host_name user password.

After you have connected to an FTP server, you should set the transfer type. This is done with the FTPASCII or FTPBINARY commands. If you will be transferring plain ASCII text files, you should use FTPASCII. By doing this, the server knows to convert the files to an ASCII format that your client computer can read. This is important because ASCII files on Windows machines are line terminated with carriage return and line feed ASCII characters, and on Unix-based machines, ASCII files are line terminated with only line feed characters. If you are connecting to a mainframe, text files are stored in EBCDIC format. Using the FTPASCII command before you transfer text files will ensure that you receive them in the ASCII format that is native to your client machine. Using the FTPASCII command is as simple as the following statement:

FTPASCII.

If you need to transfer binary data such as word processing documents or spreadsheet files, you should use the FTPBINARY command before transmitting files. This ensures that no ASCII translation is performed on your file during the transfer.

Another useful command is FTPCD. It allows you to change the directory on the FTP server that you are connecting to. Here’s an example:

FTPCD USING `\ftp\data\interfaces`.

You should make sure that you use the correct directory naming structure for the FTP host that you are connecting to. The above example is a directory name on a Unix based host. If it were a Windows based server, you might use something like `C:\datafiles\output`, or on a mainframe you might use `’idy2v.data.acct’`.

The FTPGET and FTPPUT commands actually perform the file transfer operations. You should use FTPGET to get a file from an FTP server, and FTPPUT to send a file to an FTP server. Here are examples of these commands in complete statements:

FTPGET USING `order.dat`.

DISPLAY `FTPGET TCPIP-RETURN-CODES: ` & TCPIP-RETURN-CODES.

FTPPUT USING `order.dat`.

DISPLAY `FTPPUT TCPIP-RETURN-CODES: ` & TCPIP-RETURN-CODES.