我有一个 Java 程序,它使用 ftp4j 库将图片上传到 FTP 服务器。有时图像很好,但有时它们的下半部分要么是黑色的,要么根本不存在(有点像剪切)。它可能是什么原因以及如何解决它?上传模式设置为二进制。
编码
try{
client.connect(serverName);
client.login(serverUser, serverPass);
System.out.println("Connection with the server created");
if(serverHome == null){
serverHome = "";
}
client.changeDirectory(serverHome+"/screenshotuploader/users/"+user);
int count = new IOCounter().FileReader("count.txt");
client.setType(FTPClient.TYPE_BINARY);
client.upload(new java.io.File("screenshots/screen"+(count-1)+".png"));
System.out.println("Screenshot nr "+(count-1)+" has been uploaded");
SystemTray notif = new SystemTray();
notif.Bubble(0);
Clipboard.setClipboard(new IOCounter().FTPtoHTTP(serverName)+
"/screenshotuploader/users/"+user+"/screen"+(count-1)+".png");
//Shows entire file list in the folder
String dir = client.currentDirectory();
FTPFile[] list = client.list();
for (int i=0; i < list.length; i++){
System.out.println(list[i]);
}
client.disconnect(true);
}
catch (IllegalStateException | IOException | FTPIllegalReplyException |
FTPException | FTPDataTransferException | FTPAbortedException |
FTPListParseException e){
e.printStackTrace();
System.out.println("Something went wrong with uploading the image");
SystemTray notif = new SystemTray();
notif.Bubble(1);
}
我没有尝试过主动被动模式,因为我在路由器后面,我想我不能像那样建立主动连接。