/**
* 登录FTP
*
* @param ftpUrl
* @param ftpUserName
* @param ftpPwd
* @return
* @throws SocketException
* @throws IOException
*/
public static FTPClient loginFtp(String ftpUrl, String ftpUserName,
String ftpPwd) throws SocketException, IOException {
FTPClient client = new FTPClient();
// 让FTP支持中文 必须放在connect之前 否则无效
client.setControlEncoding("UTF-8");
client.connect(ftpUrl);
boolean login = client.login(ftpUserName, ftpPwd);
if (!login) {
return null;
}
client.enterLocalPassiveMode(); // 更改获取模式
return client;
}
public upload(){
FTPClient client = loginFtp(so.getFtpUrl(), so.getFtpUserName(), so.getFtpPwd());
InputStream is = new ByteArrayInputStream("string test".getBytes("utf-8"));
client.changeWorkingDirectory(so.getFromPath());
client.storeFile(e.getKey().toString(), is);
}