///////////////////////////////////////////////////////////////////////////////////// // ftp.cs // // Originally translated from a TSL script. // Last modified 9/17/99 // // This script will get host name, user name, password, and other relevant FTP // info from the user and then get or send a file. // function ftptest() { var sysname, uname, pword, transferMode, action; te.displaynl("This script uploads and downloads files using the FTP protocol."); te.displaynl("It assumes the host is a UNIX or similar system."); te.displaynl(""); te.displaynl(""); // get initial connection info sysname = te.read("Enter system (name or IP address): ", true); te.displaynl("\nEnter your username for system " + sysname); uname = te.read("or leave blank for anonymous login: ", true); te.displaynl(" "); if (len(uname) == 0) { uname = "anonymous"; te.displaynl("Enter your email address for use as a password. "); } else te.displaynl("Enter password for user " + uname + " on system " + sysname +" "); pword = te.read("The password will not display on screen: ", false); // set system configuration FTSetProtocol("FTP"); // Use FTP for transfers FTSetXferStat(true); // Display FTP status box for transfers FTSetSync(true); // Wait until transfer is complete before continuing FTSetHostName(sysname); // Host to connect to if (FTGetHostName() == "") { te.Displaynl("You must enter an FTP hostname or IP address to transfer files."); return; } FTSetUserName(uname); // FTP username FTSetPassword(pword); // FTP password dprintln("protocol = ", FTGetProtocolName(FTGetProtocolID() + 1)); dprintln("sysname = ", FTGetHostName(), " user = ", FTGetUserName(), " pswrd = ", FTGetPassword()); if (FTGetPassword == "") { te.Displaynl("You must enter a password to log into an FTP server."); return; } te.displaynl("\n"); transferMode = te.read("Enter 'a' for ASCII or 'b' for Binary: ", true); if (transferMode == "a" || transferMode == "A") FTSetAsciiMode(true); else FTSetAsciiMode(false); // find out what to do with the file te.displaynl(""); te.displaynl("Do you want to (G)et or (S)end a file?"); action = te.read("Press any other letter or number to quit TinyTERM: ", true); te.displaynl(""); // act on the request if (action == "g" || action == "G") ftptest_grab(); else if (action == "s" || action == "S") ftptest_give(); // termination of script message te.displaynl("Exiting to system . . ."); return(0); } function ftptest_grab() { var hostdir, pcdir; // find out what is wanted file = te.read("Enter filename to get: ", true); te.displaynl(" "); hostdir = te.read("Enter the directory to get it from: ", true); te.displaynl(" "); pcdir = te.read("Enter location directory on the PC (default is C:\\Temp): ", true); // check for directory existence. assumes C:\Temp exists if (!isdir(pcdir) || len(pcdir) == 0) { dprintln("getting default dir "); pcdir = "C:\\Temp"; } if (isdir(pcdir)) { // get the file dprintln("receiving file = <", hostdir, "/", file, "> directory = <", pcdir, ">"); FTRecv(hostdir + "/" + file, pcdir); } else te.displaynl("Invalid directory " + pcdir); return(0); } function ftptest_give() { var tfile, file; // find out what is wanted file = te.read("Enter filename to send: ", true); te.displaynl(" "); pcdir = te.read("Enter the local directory it is in,\n\rdefault is current working directory: ", true); if (_sizeof(pcdir) == 0 || !isdir(pcdir)) pcdir = getuserdir(); // check for directory existence and use current directory if not te.displaynl(" "); hostdir = te.read("Enter the directory on the host to put the file in,\n\rdefault is login directory: ", true); if (_sizeof(hostdir) == 0) hostdir = "."; tfile = fconcat(pcdir, fhead(file), fext(file)) ; if (exists(tfile) || fext(tfile) == "*" || fhead(tfile) == "*") { // send the file dprintln("sending file = <", tfile, "> directory = <", hostdir, ">"); FTSend(tfile, hostdir,0); return(0); } else te.displaynl("Cannot find file(s) " + tfile); } ftptest();