简体   繁体   English

使用Apache Commons文件上传

[英]Using Apache Commons File Upload

I am trying to upload a pdf file to ftp server. 我正在尝试将pdf文件上传到ftp服务器。 My code is somewhat like this: 我的代码有点像这样:

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");
            }
        }    
}

The method shows that the file is uploaded, The method executes fine. 该方法表明文件已上传,该方法执行良好。 and shows the completion message. 并显示完成消息。 But I cannot find the file in ftp. 但是我在ftp中找不到文件。 It means the file is not uploaded. 这表示文件未上传。 What is wrong with my code. 我的代码有什么问题。 Please help. 请帮忙。

Try calling enterLocalPassiveMode after login. 登录后尝试调用enterLocalPassiveMode。

It could be many things, as FTP servers are unpredictable little monsters, but that's what it smells like to me. 可能有很多事情,因为FTP服务器是不可预测的小怪物,但这对我来说就像是。

It doesn't look like your File path would be valid on the remote system as a file name, or it isn't storing it as expected based upon the file path name format. 看起来您的文件路径在远程系统上不能作为文件名有效,或者根据文件路径名格式未按预期存储。 Try using just the file name without the "pdf\\\\" prefix when saving to the remote system. 保存到远程系统时,请尝试仅使用不带“ pdf \\\\”前缀的文件名。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将默认文件设置为使用Apache Commons文件上传进行上传 - Set default File to upload using Apache commons file upload 如何使用Apache Commons从servlet上传文件来上传文件? - How to upload a file using Apache Commons file upload from a servlet? Apache commons文件上传替代品 - Apache commons file upload alternatives Java:使用Restlet + Apache Commons FileUpload二进制文件上传 - Java: Binary File Upload using Restlet + Apache Commons FileUpload 使用Apache Commons File Upload解析multipart / form-data - Parsing multipart/form-data using Apache Commons File Upload apache commons ftp客户端文件上传问题 - apache commons ftp client file upload issue Apache Commons文件上传 - Stream意外结束 - Apache Commons File Upload - Stream ended unexpectedly 当使用 Apache Commons VFS 进行 SFTP 上传时,必须面对 org.apache.commons.vfs2.FileSystemException:找不到带有 URI 的文件 - When SFTP Upload using Apache Commons VFS have to face org.apache.commons.vfs2.FileSystemException: Could not find file with URI Apache Commons File Upload-上传后获取正确的文件 - Apache Commons File Upload-getting correpted file after upload 使用 java 中的 Apache 共享网络库将文件上传到 ftp 服务器中的特定目录 - upload file to a specific directory in ftp server using Apache Commons Net library in java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM