我想用Apache Commons Net实现一个FTP客户端来上传数据。 连接和登录到FTP服务器工作正常。 但上传不起作用。 这些文件与原件有点大。 并且文件已损坏。 我尝试了一个图像,一个视频和一个文本文件。只有文本文件没问题。Apache Commons FTP问题
现在我看到在调试
boolean tmp=client.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
给我false
。所以它不能设置。为什么? (也许这是没有问题吗?)
这里,我的代码的其余
client=new FTPClient();
try {
int reply;
client.connect(url, port);
reply = client.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply))
{
client.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
client.login(user, pw);
boolean xxx=client.setFileTransferMode(FTPClient.BINARY_FILE_TYPE);
client.setControlKeepAliveTimeout(300);
client.enterLocalPassiveMode();
if (client.isConnected())
{
try {
File file=new File(<FILE>);
FileInputStream inputStream = new FileInputStream(file);
OutputStream outputStream = client.storeFileStream(file.getName());
byte[] buffer = new byte[4096];
int l;
while((l = inputStream.read(buffer))!=-1)
{
outputStream.write(buffer, 0, l);
}
inputStream.close();
outputStream.flush();
outputStream.close();}
嗨,我试过了,但是这个方法让我错误,所以模式无法设置。 – Igor
你试过这个在调用connect方法后的地方吗? –
并且在登录方法之后。 –