TelnetInputStream out=ftpClient.get("hello.txt");
RandomAccessFile ra=new RandomAccessFile("G:\\ftp\\111.txt","rw");这个就是从服务器上下载hello.txt,存为111.txt
RandomAccessFile ra=new RandomAccessFile("G:\\ftp\\111.txt","rw");这个就是从服务器上下载hello.txt,存为111.txt
解决方案 »
- 如何重写鼠标事件函数 来传递一个对象
- 几个关于关于String的问题急!!!!!!
- JSP 调用beans
- 用org.xml.sax.XMLReader如何对外部DTD文件进行验证
- 如何提高java代码效率,为提高效率应该避免的编写形式有哪些?
- 新手提问:用JAVA有没有MSDN一样的帮助文件?谢谢。
- 请教一个简单的问题,送分
- 向大家请教一个绝对简单的问题
- SOS,如何判断IP地址是来自哪一个网段的?
- 问一个关于对话框的问题
- jbuilderx开发web应用,当更新编译一类时,jbuilderx会将此更新同步到web-inf/classes下,但如果是properties或xml文件,那么如何同步了?
- 我想显示指定路径的所有文件和文件夹
import java.io.*;
import java.io.IOException;
import java.util.StringTokenizer;
import sun.net.ftp.*;
import java.util.ArrayList;
import sun.net.TelnetOutputStream;
/**
* 一个连接FTP的类
* 只有上传文件
* 通过测试
*
*
* @author jiaoyan
* @version 1.0
*/
public class Ftpupload {
FtpClient client;
private String host="123.456.789.133";//FTP服务器IP
private String username="anonymous";//FTP用户名字
private String password=" ";//FTP密码
private String path = "/wanglei"; //文件要放哪个目录
private int port = 21; //FTP端口
/**
* 连接服务器方法
*/
public void connect() {
try {
client = new FtpClient(host);
client.login(username, password);
//设置成2进制传输
client.binary();
client.cd(path);
System.out.println("登陆成功");
}
catch (FtpLoginException e) {
System.out.println("无权限相连接" + e.getMessage());
}
catch(IOException e){
System.out.println("连接失败"+e.getMessage());
}
catch(SecurityException e){
System.out.println("用户名字或者密码不对");
} }
/**
* 上传文件
* @param fileName String 文件名字
* @param filePath String 文件路径
* @return boolean
*/
public boolean upLoad(String fileName,String filePath) {
File localFile = new File(filePath); try {
TelnetOutputStream os = client.put(fileName);
java.io.File file_in = new java.io.File(filePath);
FileInputStream is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ( (c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
is.close();
os.close();
System.out.println("传送成功"); }
catch (Exception e) {
System.out.println("上传文件出错"+e.getMessage());
return false;
}
return true;
}
public void closeServer()throws Exception{
if(client!=null){
client.closeServer();
System.out.println("FTP已经关闭");
}
}
}
import java.io.*;
import java.io.IOException;
import java.util.StringTokenizer;
import sun.net.ftp.*;
import java.util.ArrayList;
import sun.net.TelnetOutputStream;
import sun.net.TelnetInputStream;/**
* 一个连接FTP的类
* 只有上传文件
* 通过测试
*
*
* @author jiaoyan
* @version 1.0
*/
public class Ftp{
FtpClient client;
Config cfg = Config.getConfig(); private String host = cfg.getProperty("account.ftp.ip"); //FTP服务器IP
private String username = cfg.getProperty("account.ftp.username"); //FTP用户名字
private String password = cfg.getProperty("account.ftp.password"); //FTP密码
private String path = cfg.getProperty("account.ftp.path"); //文件要放哪个目录
private int port = new Integer(cfg.getProperty("account.ftp.port")).intValue(); //FTP端口
/**
* 连接服务器方法
*/
public void connect() {
try {
client = new FtpClient(host);
client.login(username, password);
//设置成2进制传输
client.binary();
client.cd(path);
System.out.println("登陆成功");
}
catch (FtpLoginException e) {
System.out.println("无权限相连接" + e.getMessage());
}
catch (IOException e) {
System.out.println("连接失败" + e.getMessage());
}
catch (SecurityException e) {
System.out.println("用户名字或者密码不对");
} } /**
* 上传文件
* @param fileName String 文件名字
* @param filePath String 文件路径
* @return boolean
*/
public boolean upLoad(String fileName, String filePath) {
File localFile = new File(filePath); try {
TelnetOutputStream os = client.put(fileName);
java.io.File file_in = new java.io.File(filePath);
FileInputStream is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ( (c = is.read(bytes)) != -1) {
os.write(bytes, 0, c);
}
is.close();
os.close();
System.out.println("传送成功"); }
catch (Exception e) {
System.out.println("上传文件出错" + e.getMessage());
return false;
}
return true;
} public boolean download(String fileName, String filePath) {
try {
TelnetInputStream out = client.get(fileName);
RandomAccessFile ra = new RandomAccessFile(filePath, "rw");
}
catch (Exception e) {
System.out.println("下载文件出错" + e.getMessage());
return false;
}
return true; } public void closeServer() throws Exception {
if (client != null) {
client.closeServer();
System.out.println("FTP已经关闭");
}
}
}