import java.io.*;import org.apache.commons.net.ftp.*;
public class ftpTest { public static boolean uploadFile(String url,int port,String username, String password, String path, String filename, InputStream input) {
boolean success = false;
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(url, port);//连接FTP服务器
//如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
ftp.login(username, password);//登录
reply = ftp.getReplyCode(); //530
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(path);
ftp.storeFile(filename, input);

input.close();
ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}
public static boolean downFile(String url, int port,String username, String password, String remotePath,String fileName,String localPath) {
boolean success = false;
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(url, port);
//如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
ftp.login(username, password);//登录
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(remotePath);//转移到FTP服务器目录
FTPFile[] fs = ftp.listFiles();
for(FTPFile ff:fs){
if(ff.getName().equals(fileName)){
File localFile = new File(localPath+"/"+ff.getName());

OutputStream is = new FileOutputStream(localFile); 
ftp.retrieveFile(ff.getName(), is);
is.close();
}
}

ftp.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}
return success;
}

//测试上传
public void testUpLoadFromDisk(){
try {
FileInputStream in=new FileInputStream(new File("D:/test.txt"));
boolean flag = uploadFile("127.0.0.1", 21, "administrator", "", "D:/ftp", "test.txt", in);
System.out.println(flag);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}

//测试下载
public void testUpLoadFromString(){
try {
InputStream input = new ByteArrayInputStream("test ftp".getBytes("utf-8"));
boolean flag = uploadFile("127.0.0.1", 21, "administrator", "", "D:/ftp", "test.txt", input);
System.out.println(flag);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}

    public static void main(String[] args) { 
     ftpTest t = new ftpTest();
     t.testUpLoadFromDisk();
     t.testUpLoadFromString();
    } 
}安装IIS后, 无异常。不过, 就是返回FALSE。是帐户密码那里错了吗?