【发布时间】:2013-04-28 22:07:58
【问题描述】:
我在将文件上传到 FTP 服务器时遇到了一些问题。
我编写的这段代码应该连接到 FTP 服务器、登录并使用 Apache Commons Net FTPClient 上传文件:
FTPClient client = new FTPClient();
client.connect("somesite.com");
client.login("user", "password");
System.out.println("connected");
client.cwd("images/bar");
System.out.println("cwd succesful. Full reply: "+client.getReplyString());
FileInputStream fis = new FileInputStream(new File(System.getProperty("user.dir")+File.separator+"current_690.jpg"));
client.storeFile(image_name, fis);
System.out.println("Succesful store. Full reply: "+client.getReplyString());
到终端的输出是:
connected
cwd succesful. Full reply: 250 OK. Current directory is /images/bar
Succesful store. Full reply: 226-File successfully transferred
226 3.190 seconds (measured here), 9.99 Kbytes per second
问题是,如果我去我的user.dir 并打开current_690.jpg,它会正确显示图像,但是如果我下载我刚刚用我的 FTPClient 上传的图像,当我打开它时,操作系统会显示@987654325 @
事实上,我注意到在我的电脑上我的图像大小是32708 字节,但在服务器上它显示我32615 字节,所以我认为图像的最后一部分没有被上传。
为什么?我错过了什么吗?
【问题讨论】:
标签: java ftp apache-commons-net