Using the FTPS Package
Example 15 – Retrieving a Document Securely via FTPS
This example establishes a secure connection and then retrieves a document from the server using the RETR command.
 
RWWinSockInfo winsock; //1
RWSecureSocketPackageInit secsock;
 
RWSecureSocketPackageInit::seedRNGFromFile("seedfile.dat"); //2
 
RWSecureSocketContext context; //3
RWFtpsClient client(context);
 
client.setTimeout(60000); //4
 
RWInetAddr addr("ftp.roguewave.com"); //5
RWFtpsReply reply = client.connect(addr);
 
reply = client.auth(); //6
reply = client.user(user);
reply = client.pass(pass);
 
reply = client.pbsz(); //7
reply = client.prot("P");
 
RWFtpsDataReply dataReply = client.nlst("/pub/foo"); //8
dataReply = client.retr(remoteFile); //9
RWPortal portal = dataReply.getPortal();
 
RWFtpsDataReply dataReply = client.stor(localFile); //10
dataReply.getPortal().sendAtLeast("data");
dataReply = client.dataClose();
 
 
RWFtpsReply reply = client.quit(); //11
//1 Initialize winsock (if necessary) and the Secure Sockets package.
//2 Seed the Random Number Generator (RNG) with the data in the provided file.
//3 Establish an SSL/TLS context and create the FTPS client.
//4 Set a timeout in milliseconds for the client to wait to connect.
//5 Create an Internet address and provide it to an RWFtpsReply object, then connect to the server.
//6 Request a secure session using the AUTH protocol command. Once the server confirms the connection, the client then provides login credentials using the standard protocol commands USER and PASS.
//7 Encrypt the data channel. The command PBSZ sets the protection buffer size to 0 as required by the FTPS standard. This command must be followed by the PROT command to secure the data channel. Note that the protection level is set to “P” or “private.”
//8 Use the specialization class RWFtpsDataReply to receive data returned by the server, in this case, the list of files. This object contains an RWPortal that acts as the connection to the remote server.
//9 Retrieve a file from the server. (See Chapter 4, “Portals,” in the Essential Networking Module User's Guide for information on retrieving the contents of the portal.
//10 Put a file on the server using the protocol command STOR. This method must be followed by a call to dataClose() to complete the data transfer.
//11 Closes the connection.
Example 16 – Retrieving Server Information via FTPS
This example illustrates retrieving information from the server, continuing after steps 1 - 7 of Example 15.
 
...
reply = client.cwd("/pub/foo"); //8
 
RWFtpsPwdReply pwdReply = client.pwd(); //9
 
reply = client.quit(); //10
 
//8 Change directories to foo.
//9 Use the specialization class RWFtpsPwdReply to receive the results of the PWD protocol command.
//10 Close the connection.