public static boolean uploadFile(String originFileName, InputStream input) {
String ip = WslaContants.WslaFtpConnection.IP;
int port = WslaContants.WslaFtpConnection.PORT;
String user = WslaContants.WslaFtpConnection.USER;
String pwsswd = WslaContants.WslaFtpConnection.PWSSWD;
String lj = WslaContants.WslaFtpConnection.LJ;
FTPClient ftpClient = new FTPClient();
boolean success = false;
try {
//连接服务器
ftpClient.connect(ip, port);
//登入
ftpClient.login(user, pwsswd);
//是否成功登录FTP服务器
int replyCode = ftpClient.getReplyCode();
System.out.println(replyCode);
if (!FTPReply.isPositiveCompletion(replyCode)) {
return success;
}
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);
ftpClient.changeWorkingDirectory(lj);
ftpClient.storeFile(originFileName, input);
ftpClient.logout();
success = true;
} catch (IOException e) {
e.printStackTrace();
}
return success;
}
注意:如果是匿名的话:
user为:anonymous
ftp路径写法:pub/
默认端口:21
如果是匿名那么pssword为:""空