Apache下的FTP上传文件,使用FTPClient的appendFileStream方法返回输出流为空?望高手指点。急!!!! 10
望高手指点。拜谢!/***上传文件到服务器,新上传和断点续传*@paramremoteFile远程文件名,在上传之前已经将服务器工作目录做了改变*@paramlocalF...
望高手指点。拜谢!
/**
* 上传文件到服务器,新上传和断点续传
* @param remoteFile 远程文件名,在上传之前已经将服务器工作目录做了改变
* @param localFile 本地文件File句柄,绝对路径
* @param processStep 需要显示的处理进度步进值
* @param ftpClient FTPClient引用
* @return
* @throws IOException
*/
public uploadStatu uploadFile(String remoteFile,File localFile,FTPClient ftpClient,long remoteSize) throws IOException{
uploadStatu status;
//显示进度的上传
long step = localFile.length() / 100;
long process = 0;
long localreadbytes = 0L;
System.out.println("localFile本地文件绝对路径:"+localFile);
RandomAccessFile raf = new RandomAccessFile(localFile,"r");
///输出流out为空,无法获取。。。。
OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"),"utf-8"));
//断点续传
if(remoteSize>0){
ftpClient.setRestartOffset(remoteSize);
process = remoteSize /step;
raf.seek(remoteSize);
System.out.println("进入断点续床。。。。。。。。。");
localreadbytes = remoteSize;
}
System.out.println("没有进入断点续床。。。。。。。。。");
byte[] bytes = new byte[1024];
// System.out.println("每次读入字节:"+bytes.length);
int c;
while((c = raf.read(bytes))!= -1){
System.out.println("每次读入字节:"+c);
System.out.println("输出流:"+out);
out.write(bytes,0,c);
localreadbytes+=c;
if(localreadbytes / step != process){
process = localreadbytes / step;
System.out.println("上传进度:" + process);
//TODO 汇报上传状态
}
}
out.flush();
raf.close();
out.close();
boolean result =ftpClient.completePendingCommand();
if(remoteSize > 0){
status = result?uploadStatu.Upload_From_Break_Success:uploadStatu.Upload_From_Break_Failed;
}else {
status = result?uploadStatu.Upload_New_File_Success:uploadStatu.Upload_New_File_Failed;
}
return status;
} 展开
/**
* 上传文件到服务器,新上传和断点续传
* @param remoteFile 远程文件名,在上传之前已经将服务器工作目录做了改变
* @param localFile 本地文件File句柄,绝对路径
* @param processStep 需要显示的处理进度步进值
* @param ftpClient FTPClient引用
* @return
* @throws IOException
*/
public uploadStatu uploadFile(String remoteFile,File localFile,FTPClient ftpClient,long remoteSize) throws IOException{
uploadStatu status;
//显示进度的上传
long step = localFile.length() / 100;
long process = 0;
long localreadbytes = 0L;
System.out.println("localFile本地文件绝对路径:"+localFile);
RandomAccessFile raf = new RandomAccessFile(localFile,"r");
///输出流out为空,无法获取。。。。
OutputStream out = ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"),"utf-8"));
//断点续传
if(remoteSize>0){
ftpClient.setRestartOffset(remoteSize);
process = remoteSize /step;
raf.seek(remoteSize);
System.out.println("进入断点续床。。。。。。。。。");
localreadbytes = remoteSize;
}
System.out.println("没有进入断点续床。。。。。。。。。");
byte[] bytes = new byte[1024];
// System.out.println("每次读入字节:"+bytes.length);
int c;
while((c = raf.read(bytes))!= -1){
System.out.println("每次读入字节:"+c);
System.out.println("输出流:"+out);
out.write(bytes,0,c);
localreadbytes+=c;
if(localreadbytes / step != process){
process = localreadbytes / step;
System.out.println("上传进度:" + process);
//TODO 汇报上传状态
}
}
out.flush();
raf.close();
out.close();
boolean result =ftpClient.completePendingCommand();
if(remoteSize > 0){
status = result?uploadStatu.Upload_From_Break_Success:uploadStatu.Upload_From_Break_Failed;
}else {
status = result?uploadStatu.Upload_New_File_Success:uploadStatu.Upload_New_File_Failed;
}
return status;
} 展开
展开全部
ftp服务器的问题,建议:
更换ftp服务器
调整ftp用户操作权限;权限可能不够
更换ftp服务器
调整ftp用户操作权限;权限可能不够
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
ftpClient.enterLocalPassiveMode(); 将这句去掉
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你好,你的这个问题解决了吗?我也遇到, out.write(bytes, 0, c); out = ftpClient.appendFileStream(new String(remoteFile.getBytes("GBK"), "iso-8859-1"));out 报空,求指点,谢谢.
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询