import java.io.IOException;
import java.util.Properties;
import com.enterprisedt.net.ftp.FTPClient;
import com.enterprisedt.net.ftp.FTPConnectMode;
import com.enterprisedt.net.ftp.FTPException;
import com.enterprisedt.net.ftp.FTPMessageCollector;
import com.enterprisedt.net.ftp.FTPTransferType;
public class TestFtp {
/**
* @param args
*/
public static void main(String[] args) {
String FTPSERVER = "192.168.11.11";
/**ftp server 端口,ftp默认的端口都是21*/
int FTPPORT = 21;
/**ftp 用户名 */
String FTPUSER ="userName";
/**ftp 用户密码 */
String FTPPSWD ="******";
/**文件存放的路径*/
String filePath="D:/projects/TestProject/";
/**文件名*/
String fileName ="temp.txt";
/**可以用以下语句求出当前路径地址*/
Properties p = System.getProperties();
System.out.println("path: "+p.getProperty("user.dir"));
ftp.quit();
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (FTPException e) {
e.printStackTrace();
}
}
}
以上代码在JDK1.42中测试通过。
注意:这三句代码
和
FTPClient ftp= new FTPClient(FTPSERVER,FTPPORT);意思一样
但最好不要用后一句,是不被推荐使用的。我使用上面一句就报了
The FTP client has already been connected to the server.
The requested action must be performed before a connection is established.
异常。
下载做法差不多了。自己摸索下吧~~
posted on 2008-05-05 11:04 无声 阅读(6399) 评论(0) 编辑 收藏 所属分类: 职场生活