美好的一天。我已将org.apache.commons.net.ftp.FTP导入到我的项目中,并且在将zip文件上传到FTP时遇到了一些问题。 当它上传小文件(<100MB)时,它工作正常。但是当涉及到更大的文件(> 500MB)时,它将在那里停止,而不返回并执行剩余的操作,即使文件被传输到服务器也是如此。 以及传输完成后函数/ FTP如何确认?无论如何要检查它吗?
public class zipFTP
{
public boolean uploadFile(String ht, String usr, String ps, String fpath, String uploadloc)
{
FTPClient client = new FTPClient();
FileInputStream fis = null;
writeLog nLog = new writeLog();
String channel = "FTP";
boolean completed = false;
//client.setBufferSize(1048576);
client.setControlKeepAliveReplyTimeout(300);
//System.out.println(client.getBufferSize());
try
{
nLog.writeToLog(dumptoFTP.filename, channel, "Uploading...");
client.connect(ht);
client.login(usr, ps);
client.enterLocalPassiveMode();
client.setFileType(FTP.BINARY_FILE_TYPE);
fis = new FileInputStream(fpath);
completed = client.storeFile(uploadloc, fis);
//client.completePendingCommand(); //to complete the transaction entirely
if(completed)
{
if (dumptoFTP.isSysLog)
System.out.println("File uploaded");
nLog.writeToLog(dumptoFTP.filename, channel, "File uploaded");
}
fis.close();
}
catch (IOException e)
{
e.printStackTrace();
if (dumptoFTP.isSysLog)
System.out.println("Upload failed");
nLog.writeToLog(dumptoFTP.filename, channel, "Upload failed");
nLog.writeToLog(dumptoFTP.filename, channel, e.toString());
}
finally
{
try
{
if(client.isConnected())
{
client.logout();
client.disconnect();
}
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
return completed;
}
}
答案 0 :(得分:0)
结束,setBufferSize()
可以解决问题