java ftp 上传文件后,文件名称被改变
在网上找的代码,用的是 commons-io-1.4,上传文件至ftp后,文件内容正确,但是,文件名称从'test.txt'变成了‘pureftpd.5515257a.51.0000’,请帮助分析一下,到底是什么原因,十分感谢
public static boolean upload(String url, int port, String username, String password, String ftpPath, String filename) {
FTPClient ftpClient = new FTPClient();
InputStream fis = null;
boolean flag = false;
try {
ftpClient.connect(url);
boolean reflag = ftpClient.login(username, password);
System.out.println("reflag: " + reflag);
ftpClient.enterLocalPassiveMode();
File srcFile = new File(filename);
fis = new FileInputStream(srcFile);
// 设置文件类型(二进制)
ftpClient.setFileType(FTPClient.ASCII_FILE_TYPE);
// String name = srcFile.getName();
flag = ftpClient.storeUniqueFile(ftpPath, fis); //.storeFile(ftpPath, fis);
} catch (IOException e) {
e.printStackTrace();
flag = false;
throw new RuntimeException("FTP客户端出错!", e);
} finally {
IOUtils.closeQuietly(fis);
try {
ftpClient.disconnect();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException("关闭FTP连接发生异常!", e);
}
}
return flag;
}
public static void main(String[] str) {
TestFTp test = new TestFTp();
test.testFtpUpload();
}
public void testFtpUpload() {
String url = "333.333.33.33";
int port = 21;
String username = "**********";
String password = "*******";
// 上传到ftp服务器路径
String ftpPath = "/ttttttttt/";
// 本地需上传文件路径
String filename = "C:/test.txt";
boolean flag = FtpUtil.upload(url, port, username, password, ftpPath, filename);
System.out.println(flag);
}
...全文


