日期:2014-05-20  浏览次数:21152 次

java 实现ftp上传文件时,上传内容为空
java   实现ftp上传文件时,在本地用ftp服务器测试时可以实现,但向服务器上传时,上传内容为o   kb,找了很长时间,求助??代码如下:
public     void   gg(String   host,String   userID,String   password,String   directory,String   fileName   ,String   strDate   ){
try       {      

       
    File   newfile=new   File(directory);
    if(!newfile.exists()){
    newfile.mkdir();
    }

FtpClient       ftpClient       =       new       FtpClient(host,21);      
   
//ftpClient.openServer(host);       //       connect       to       FTP       server      
ftpClient.login(userID,       password);       //       login      
ftpClient.binary();       //       set       to       binary       mode       transfer      
ftpClient.cd(directory);       //       change       directory      

     
        Date   d=new   Date();
        SimpleDateFormat   dateFm   =   new   SimpleDateFormat( "yyyyMMddhhmm ");
          strDate=dateFm.format(d).toString();   //新生成的文件名
       
File       file       =       new       File(fileName);      
TelnetOutputStream       out       =       ftpClient.put(file.getName());      
FileInputStream       in       =       new       FileInputStream(file);  
byte[]   bytes   =   new   byte[1024];
int       c       =       0;      
while       ((c       =       in.read(bytes))       !=       -1)       {      
out.write(bytes,   0,   c);      
}      
in.close();      
out.close();      
        ftpClient.closeServer();  
        System.out.println( ".上传成功.. ");
}       catch       (Exception       exception)       {      
        exception.printStackTrace();      
}

------解决方案--------------------
是不是权限不对!
------解决方案--------------------
我也遇到这种问题,这种情况只有在向一个空的目录第一次写文件的时候,才会发生!
不过我通过向空目录写一个空的文件,然后再执行一次自身已经解决了这个问题。
------解决方案--------------------
只有在向一个空的目录第一次写文件的时候,才会发生! 

------解决方案--------------------
还有这种事啊,学习