TestFTPUser.mesa
Bob Hagmann March 18, 1985 3:47:49 pm PST
Hal Murray, April 11, 1986 8:43:18 am PST
DIRECTORY
BasicTime,
FTP,
IO,
Rope,
UserCredentials;
TestFTPUser: CEDAR PROGRAM
IMPORTS FTP, IO, Rope, UserCredentials =
BEGIN
ROPE: TYPE = Rope.ROPE;
ConnectAndGoAway: PROC [hostName: ROPE] RETURNS [remoteHerald: ROPE] = {
ftpHandle: FTP.Handle;
[h: ftpHandle, remoteHerald: remoteHerald] ← FTP.CreateFromName[
hostName: hostName, localHerald: "Cedar FTP Calling"] ;
FTP.Destroy[ftpHandle];
};
ListObject: TYPE = RECORD [
directory: ROPE,
name: ROPE,
version: ROPE,
create: BasicTime.GMT
];
ConnectListAndGoAway: PROC [hostName: ROPE, directory: ROPE, pattern: ROPE] = {
ftpHandle: FTP.Handle;
remoteHerald: ROPE;
properties: FTP.PropertySet;
name, password: Rope.ROPE;
nameList: LIST OF REF ListObject ← NIL;
enumProc: PROCEDURE [h: FTP.Handle] = {
create: BasicTime.GMT;
directory: ROPE;
name: ROPE;
version: ROPE;
item: REF ListObject;
create ← h.GetDateProperty[prop: createDate, list: remote];
directory ← h.GetTextProperty[prop: directory, list: remote];
name ← h.GetTextProperty[prop: nameBody, list: remote];
version ← h.GetTextProperty[prop: version, list: remote];
item ← NEW[ListObject ← [directory, name, version, create]];
nameList ← CONS[item, nameList];
};
[name, password] ← UserCredentials.Get[];
[h: ftpHandle, remoteHerald: remoteHerald] ← FTP.CreateFromName[hostName: hostName, localHerald: "Cedar FTP Calling"] ;
properties[createDate] ← TRUE;
properties[directory] ← TRUE;
properties[nameBody] ← TRUE;
properties[version] ← TRUE;
FTP.SetDesiredProperties[h: ftpHandle, props: properties, userDefinedProps: NIL];
FTP.SetTextProperty[ftpHandle, directory, directory];
FTP.SetTextProperty[ftpHandle, nameBody, pattern];
FTP.SetTextProperty[ftpHandle, userName, name];
FTP.SetTextProperty[ftpHandle, userPassword, password];
FTP.Enumerate[h: ftpHandle, noteFile: enumProc];
FTP.Destroy[ftpHandle];
};
ConnectRetrieveAndGoAway: PROC [hostName: ROPE, directory: ROPE, file: ROPE, version: ROPE] RETURNS [fileRope: ROPE] = {
ftpHandle: FTP.Handle;
remoteHerald: ROPE;
properties: FTP.PropertySet;
name, password: Rope.ROPE;
confirmProc: FTP.ConfirmProc = {
 PROCEDURE [h: Handle] RETURNS [confirm: BOOLEAN];
confirm ← TRUE;
};
transferProc: FTP.TransferProc = {
PROCEDURE [h: Handle, stream: IO.STREAM];
DO
fileRope ← Rope.Concat[fileRope, stream.GetLineRope[ ! IO.EndOfStream => EXIT]];
ENDLOOP;
};
completeProc: FTP.CompleteProc = {
PROCEDURE [h: Handle, ok: BOOLEAN];
};
[name, password] ← UserCredentials.Get[];
[h: ftpHandle, remoteHerald: remoteHerald] ← FTP.CreateFromName[hostName: hostName, localHerald: "Cedar FTP Calling"] ;
properties[createDate] ← TRUE;
properties[directory] ← TRUE;
properties[nameBody] ← TRUE;
properties[version] ← TRUE;
properties[size] ← TRUE;
FTP.SetDesiredProperties[h: ftpHandle, props: properties, userDefinedProps: NIL];
FTP.SetTextProperty[ftpHandle, directory, directory];
FTP.SetTextProperty[ftpHandle, nameBody, file];
FTP.SetTextProperty[ftpHandle, userName, name];
FTP.SetTextProperty[ftpHandle, userPassword, password];
FTP.SetTextProperty[ftpHandle, version, version];
FTP.Retrieve[h: ftpHandle, confirm: confirmProc, transfer: transferProc, complete: completeProc];
FTP.Destroy[ftpHandle];
};
END.