boolean success = false;
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(url, port);//链接ftp服务器
ftp.login(username, password);
reply = ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)){
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(path);
ftp.storeFile(fileName, input);
input.close();
ftp.logout();
success=true;
} catch (Exception e) {
e.printStackTrace();
}
finally{
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
FTPClient ftp = new FTPClient();
try {
int reply;
ftp.connect(url, port);//链接ftp服务器
ftp.login(username, password);
reply = ftp.getReplyCode();
if(!FTPReply.isPositiveCompletion(reply)){
ftp.disconnect();
return success;
}
ftp.changeWorkingDirectory(path);
ftp.storeFile(fileName, input);
input.close();
ftp.logout();
success=true;
} catch (Exception e) {
e.printStackTrace();
}
finally{
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
return success;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
try {
/*File file = new File("D:/test.txt");
file.createNewFile();*/
// FileInputStream in=new FileInputStream(file);
String url="127.0.0.1";
int port=21;
String username= "system";
String password= "system";
String path = "D:\\ftp";
String fileName= "1111.ini";
FileInputStream in=new FileInputStream(new File("D:\\千宇取色.ini"));
boolean flag = upLoad(url, port,username, password, path, fileName, in);
System.out.println(flag);
} catch (FileNotFoundException e) {
e.printStackTrace();
}