1

我正在尝试使用 FTPClient 的 storeFile(remote, local) 方法上传一个大文件(超过 8 MB),但结果是错误的。它上传了一些额外的字节。以下是带有输出的代码:

public class Main {
public static void main(String[] args) {
FTPClient client = new FTPClient();
FileInputStream fis = null;

try {

client.connect("208.106.181.143");
client.setFileTransferMode(client.BINARY_FILE_TYPE);
client.login("abc", "java");
int reply = client.getReplyCode();
System.out.println("Received Reply from FTP Connection:" + reply);

if(FTPReply.isPositiveCompletion(reply)){
    System.out.println("Connected Success");
}

client.changeWorkingDirectory("/"+"Everbest"+"/");
client.makeDirectory("ETPSupplyChain5.3-EvbstSP3");
client.changeWorkingDirectory("/"+"Everbest"+"/"+"ETPSupplyChain5.3-EvbstSP3"+"/");
FTPFile[] names = client.listFiles();
 String filename = "E:\\Nitin\\D-Drive\\Installer.rar";

fis = new FileInputStream(filename);

boolean result = client.storeFile("Installer.rar", fis);
 int replyAfterupload = client.getReplyCode();
System.out.println("Received Reply from FTP Connection replyAfterupload:" + replyAfterupload);
System.out.println("result:"+result);
for (FTPFile name : names) {
    System.out.println("Name = " + name);
  }

client.logout();

fis.close();



client.disconnect();
} catch (SocketException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
}
 }
}




o/p:
Received Reply from FTP Connection:230
Connected Success
32   /Everbest/ETPSupplyChain5.3-EvbstSP3
Received Reply from FTP Connection replyAfterupload:150
result:false
4

1 回答 1

0

首先,一个 8 Mb 的文件不是一个大文件。我设法使用这个库上传了大于 100Mb 的文件。

在带有参数setFileType的方法之前调用方法。它告诉服务器您的文件不应存储为 ASCII。storeFileBINARY_FILE_TYPE

最后,尝试关闭FileInputStream刚才的storeFile方法。并捕获该close方法的结果。

于 2012-11-07T10:51:48.040 回答