home *** CD-ROM | disk | FTP | other *** search
Java Source | 2001-03-30 | 6.9 KB | 248 lines |
- import com.ms.wfc.app.*;
- import com.ms.wfc.core.*;
- import com.ms.wfc.ui.*;
- import com.ms.wfc.html.*;
- import com.ms.com.*;
-
- import ftpte.*;
-
- /**
- * This class can take a variable number of parameters on the command
- * line. Program execution begins with the main() method. The class
- * constructor is not invoked unless an object of type 'TEConnectionSample' is
- * created in the main() method.
- */
- public class TEConnectionSample extends Form
- {
- //Interface to the ftpte COM object.
- ITEConnection m_TEConnection;
-
- public TEConnectionSample()
- {
- // Required for Visual J++ Form Designer support
- initForm();
-
- // TODO: Add any constructor code after initForm call
- //Create the TEConnection COM object.
- try
- {
- Status.addItem("Not Connected.");
- m_TEConnection = new TEConnection ();
- ftpsite.setEnabled(true);
- Connect.setEnabled(true);
- }
- catch (Exception e)
- {
- Status.addItem("Failed to create the TEConnection object.");
- System.out.println("Unexpected exception " + e);
- e.printStackTrace();
- }
- }
-
- /**
- * TEConnectionSample overrides dispose so it can clean up the
- * component list.
- */
- public void dispose()
- {
- super.dispose();
- components.dispose();
- }
-
- private void TEConnectionSample_click(Object source, Event e)
- {
-
- }
-
- private void Connect_click(Object source, Event e)
- {
- try
- {
- m_TEConnection.setHost(ftpsite.getText());
- m_TEConnection.setProtocol("FTP");
- m_TEConnection.setLogin("ftp");
- m_TEConnection.setPassword("u@ur.com");
- m_TEConnection.Connect();
-
- RemotePath.setEnabled(true);
- RemoteFolder.setEnabled(true);
- RemoteFolder.focus();
-
- Status.addItem("Connected to : " + ftpsite.getText() + " site.");
- Status.setScrollAlwaysVisible(true);
- }
- catch (Exception exp)
- {
- Status.addItem("Failed to connected to : " + ftpsite.getText() + " site.");
- Status.setScrollAlwaysVisible(true);
- }
- }
-
- private void RemotePath_click(Object source, Event e)
- {
- try
- {
- m_TEConnection.setRemoteFolder(RemoteFolder.getText());
- String strRemoteFolder = m_TEConnection.getRemoteFolder();
-
- download.setEnabled(true);
- filename.setEnabled(true);
- filename.focus();
-
- Status.addItem("Set Remote path to : " + RemoteFolder.getText());
- }
- catch(Exception exp)
- {
- Status.addItem("Failed to set remote path to : " + RemoteFolder.getText());
- }
- }
-
- private void download_click(Object source, Event e)
- {
- try
- {
- m_TEConnection.Download(filename.getText(),filename.getText());
- Status.addItem("Downloading the file.");
- Status.addItem("Check the status in CuteFTP pro Transfer Engine");
- }
- catch(Exception exp)
- {
- Status.addItem("Failed to download the file.");
- }
- }
-
- /**
- * NOTE: The following code is required by the Visual J++ form
- * designer. It can be modified using the form editor. Do not
- * modify it using the code editor.
- */
- Container components = new Container();
- RichEdit richEdit1 = new RichEdit();
- Label label2 = new Label();
- Edit ftpsite = new Edit();
- Button Connect = new Button();
- Edit RemoteFolder = new Edit();
- Button RemotePath = new Button();
- Label label4 = new Label();
- Label label1 = new Label();
- Edit filename = new Edit();
- Button download = new Button();
- ListBox Status = new ListBox();
- Label label3 = new Label();
-
- private void initForm()
- {
- this.setText("TEConnectionSample");
- this.setAutoScaleBaseSize(new Point(5, 13));
- this.setClientSize(new Point(343, 240));
- this.addOnClick(new EventHandler(this.TEConnectionSample_click));
-
- richEdit1.setBackColor(Color.INFO);
- richEdit1.setFont(new Font("MS Sans Serif", 9.0f, FontSize.POINTS, FontWeight.BOLD, false, false, false, CharacterSet.DEFAULT, 0));
- richEdit1.setForeColor(Color.ACTIVECAPTION);
- richEdit1.setLocation(new Point(16, 16));
- richEdit1.setSize(new Point(312, 24));
- richEdit1.setTabIndex(6);
- richEdit1.setTabStop(false);
- richEdit1.setText(" Java CuteFTP Pro TE Connection Sample.");
-
- label2.setLocation(new Point(16, 48));
- label2.setSize(new Point(100, 16));
- label2.setTabIndex(7);
- label2.setTabStop(false);
- label2.setText("Ftp Site:");
-
- ftpsite.setLocation(new Point(16, 64));
- ftpsite.setSize(new Point(216, 20));
- ftpsite.setTabIndex(0);
- ftpsite.setText("");
-
- Connect.setEnabled(false);
- Connect.setLocation(new Point(240, 64));
- Connect.setSize(new Point(80, 24));
- Connect.setTabIndex(1);
- Connect.setText("Connect");
- Connect.addOnClick(new EventHandler(this.Connect_click));
-
- RemoteFolder.setEnabled(false);
- RemoteFolder.setLocation(new Point(16, 104));
- RemoteFolder.setSize(new Point(216, 20));
- RemoteFolder.setTabIndex(2);
- RemoteFolder.setText("");
-
- RemotePath.setEnabled(false);
- RemotePath.setLocation(new Point(240, 104));
- RemotePath.setSize(new Point(80, 24));
- RemotePath.setTabIndex(3);
- RemotePath.setText("Remote Folder");
- RemotePath.addOnClick(new EventHandler(this.RemotePath_click));
-
- label4.setLocation(new Point(16, 88));
- label4.setSize(new Point(100, 16));
- label4.setTabIndex(8);
- label4.setTabStop(false);
- label4.setText("Remote Folder:");
-
- label1.setLocation(new Point(16, 128));
- label1.setSize(new Point(100, 16));
- label1.setTabIndex(9);
- label1.setTabStop(false);
- label1.setText("File to download:");
-
- filename.setEnabled(false);
- filename.setLocation(new Point(16, 144));
- filename.setSize(new Point(216, 20));
- filename.setTabIndex(4);
- filename.setText("");
-
- download.setEnabled(false);
- download.setLocation(new Point(240, 144));
- download.setSize(new Point(80, 24));
- download.setTabIndex(5);
- download.setText("Download <<");
- download.addOnClick(new EventHandler(this.download_click));
-
- Status.setBackColor(new Color(224, 224, 224));
- Status.setFont(new Font("MS Sans Serif", 8.0f, FontSize.POINTS, FontWeight.NORMAL, false, false, false, CharacterSet.DEFAULT, 0));
- Status.setForeColor(Color.HIGHLIGHT);
- Status.setLocation(new Point(16, 192));
- Status.setSize(new Point(304, 30));
- Status.setTabIndex(11);
- Status.setTabStop(false);
- Status.setText("listBox1");
- Status.setSelectionMode(SelectionMode.MULTI_SIMPLE);
- Status.setUseTabStops(true);
-
- label3.setLocation(new Point(16, 176));
- label3.setSize(new Point(100, 16));
- label3.setTabIndex(10);
- label3.setTabStop(false);
- label3.setText("Current Status:");
-
- this.setNewControls(new Control[] {
- label3,
- Status,
- download,
- filename,
- label1,
- label4,
- RemotePath,
- RemoteFolder,
- Connect,
- ftpsite,
- label2,
- richEdit1});
- }
-
- /**
- * The main entry point for the application.
- *
- * @param args Array of parameters passed to the application
- * via the command line.
- */
- public static void main(String args[])
- {
- Application.run(new TEConnectionSample());
- }
- }
-