一个关于Java连接FTP实现文件上传下载的问题
对于普通的ftp服务器,采用下面的代码可以实现文件上传:
import java.io.*;
import java.util.*;
import java.net.*;
import sun.net.ftp.FtpClient;
import sun.net.TelnetOutputStream;
public class TestFTP {
/** The host name of the FTP server. */
private static String host = "192.168.5.63";
/** The user ID to login to the FTP server. */
private static String userID = "sxt";
/** The password to login to the FTP server. */
private static String password = "sxt";
/** The directory on the FTP server to upload files to. */
private static String directory = "/";
/** The name of the file you want to upload. */
private static String fileName = "f://testFTP.doc";
public static void main(String[] args) {
try {
FtpClient ftpClient = new FtpClient(host,990);
//ftpClient.openServer(host); // connect to FTP server
ftpClient.login(userID, password); // login
ftpClient.binary(); // set to binary mode transfer
ftpClient.cd(directory); // change directory
File file = new File(fileName);
TelnetOutputStream out = ftpClient.put(file.getName());
FileInputStream in = new FileInputStream(file);
int c = 0;
while ((c = in.read()) != -1) {
out.write(c);
}
in.close();
out.close();
ftpClient.closeServer();
} catch (Exception exception) {
exception.printStackTrace();
}
}
}
但当ftp需要ssl加密时(使用相同的端口),就提示如下错误:
sun.net.ftp.FtpProtocolException: Welcome message: 431 Unable to negotiate secure command connection.
at sun.net.ftp.FtpClient.openServer(FtpClient.java:425)
at sun.net.ftp.FtpClient.<init>(FtpClient.java:705)
at TestFTP.main(TestFTP.java:26)
哪位高手帮忙解决一下啊,感谢!
问题点数:50、回复次数:4Top
1 楼huangdeji(活着就是等死)回复于 2005-07-21 17:46:12 得分 0
解决不了,因为我不是高手。Top
2 楼Maple99(Maple)回复于 2005-07-21 19:14:30 得分 0
不用ssl可以吗??Top
3 楼sxtbuaa(小洒)回复于 2005-07-22 08:53:49 得分 0
谢谢两位的回复!
需要与外部系统交换文件,对方的ftp服务器已经在用了,而且需要使用ssl,因为都是些保密数据。
再帮忙看看啦-_-!Top
4 楼sxtbuaa(小洒)回复于 2005-07-22 08:57:52 得分 0
是不是ftpClient没有对ssl的支持啊,如果一定要用的话是不是就要换一种别的组件或自己写呢,谢谢Top




