62,614
社区成员
发帖
与我相关
我的任务
分享
String url = "10.100.xxx.xx";
int port = 21;
String ftpusername = "xxxxxxxxxxx";
String ftppassword = "xxxxxxxxxxx";
String path = "xxxxxxxxxxxxxxxx";
FTPClient ftp = new FTPClient();
try {
int reply;
FileInputStream fileUp=new FileInputStream(new File("a.xls"));
ftp.connect(url, port);//连接FTP服务器
//如果采用默认端口,可以使用ftp.connect(url)的方式直接连接FTP服务器
ftp.login(ftpusername, ftppassword);//登录
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
}
ftp.changeWorkingDirectory(path);
ftp.storeFile("a.xls", fileUp);
fileUp.close();
ftp.logout();
System.out.println("ok");
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
}
}
}