2013-10-27 61 views
0

我想上传一个pdf文件到ftp服务器。我的代码有点像这样:使用Apache公共文件上传

public void pdfUpload(String ticket, JLabel message) {  

FTPClient client = new FTPClient(); 
     FileInputStream fis = null; 
     try { 
      client.connect("www.mydomain.com", 21); 
      client.login("user", "userpass"); 


      client.setFileType(FTP.BINARY_FILE_TYPE); // optional 


      String FileName = ticket.replace("/", "_"); 
      File fil = new File("pdf\\"+FileName+".pdf"); 
      message.setText(FileName+".pdf is being uploaded... Please wait"); 
      fis = new FileInputStream(fil); 

      String remoteFile = fil.getName(); 
      client.storeFile(remoteFile, fis); 
      client.logout(); 
      message.setText("File Uploaded sccessfully"); 
     } 

     catch (IOException e) { 
      message.setText("Failed to upload pdf file"+e); 
     } finally { 
      try { 
       if (fis != null) { 
        fis.close(); 
       } 
       client.disconnect(); 
      } catch (IOException e) { 
      message.setText("Failed to upload pdf file"); 
      } 
     }  
} 

该方法显示文件已上传,该方法执行正常。并显示完成消息。但我无法在ftp中找到该文件。这意味着文件没有上传。我的代码有什么问题。请帮忙。

回答

0

尝试在登录后调用enterLocalPassiveMode。

这可能是很多事情,因为FTP服务器是不可预测的小怪物,但这就是它对我的味道。

0

看起来您的文件路径看起来并不像您的文件路径在远程系统上作为文件名是有效的,或者它并不像预期的那样根据文件路径名格式存储它。保存到远程系统时,请尝试仅使用不带“pdf \\”前缀的文件名。

相关问题