KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > jftp > net > FtpClient


1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software
14  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
15  */

16 package net.sf.jftp.net;
17
18
19
20 public class FtpClient
21 {
22     private String JavaDoc name = "ftp";
23     private String JavaDoc password = "ftp@sourceforge.net";
24     private FtpConnection connection = null;
25
26     public FtpClient()
27     {
28     }
29
30     public void login(String JavaDoc host)
31     {
32         connection = new FtpConnection(host);
33         connection.login(name, password);
34     }
35
36     public void setUsername(String JavaDoc s)
37     {
38         name = s;
39     }
40
41     public void setPassword(String JavaDoc s)
42     {
43         password = s;
44     }
45
46     public void disconnect()
47     {
48         if(connection != null)
49         {
50             connection.disconnect();
51         }
52     }
53
54     public void cd(String JavaDoc s)
55     {
56         if(connection != null)
57         {
58             connection.chdir(s);
59         }
60     }
61
62     public String JavaDoc pwd()
63     {
64         if(connection != null)
65         {
66             return connection.getPWD();
67         }
68         else
69         {
70             return "";
71         }
72     }
73
74     public void get(String JavaDoc file)
75     {
76         if(connection != null)
77         {
78             connection.handleDownload(file);
79         }
80     }
81
82     public void put(String JavaDoc file)
83     {
84         if(connection != null)
85         {
86             connection.handleUpload(file);
87         }
88     }
89 }
90
Popular Tags