Commons Net FTP问题

4
我遇到了一个问题,看起来我的 FTP 连接是正确的,没有收到任何错误消息,但文件并没有被放置在 FTP 服务器上。
我正在使用 commons-net-ftp。
代码:
        int retCode = 0;

    FTPClient client = new FTPClient();
    client.addProtocolCommandListener(new PrintCommandListener(new PrintWriter(System.out)));

    InputStream input = null;
    try
    {
        int replyCode;

        client.connect(pHostName);

        replyCode = client.getReplyCode();
        if (!FTPReply.isPositiveCompletion(replyCode))
        {
            client.disconnect();
            logInfo("ftpFile() - FTP Server refused connection");
            retCode = 1;
        }
        else
        {
            if(client.login(pUserName, pPassword))
            {
                //default is FTP.ASCII_FILE_TYPE
                if(this.isBinaryTransfer())
                {
                    client.setFileType(FTP.BINARY_FILE_TYPE);   
                }

                // Use passive mode as default because most of us are
                // behind firewalls these days.
                client.enterLocalPassiveMode();

                input = new FileInputStream(pLocalFileName);

                if(this.isRemoveRemoteFile())
                {
                    client.deleteFile(pRemoteFileName);
                    client.getReply();
                    this.logReplyStringInfo(client.getReplyStrings(), "Removing Remote File");
                }

                if(this.isOverwriteFile())
                {
                    replyCode = client.sendCommand("-O");
                    this.logReplyStringInfo(client.getReplyStrings(), "Overwrite File");
                }

                if(!client.storeFile(pRemoteFileName, input))
                {
                    logError("ftpFile() - Not able to store the file on the server" ); 
                    retCode = 6;
                }

                input.close();
                client.logout();
                client.disconnect();
            }
            else
            {
                client.logout();
                client.disconnect();
                retCode = 3;
            }
        }
    }
    catch (FileNotFoundException fileNotFoundException)
    {
        logError("ftpFile(String, String, String, String, String)", fileNotFoundException); //$NON-NLS-1$

        fileNotFoundException.printStackTrace();
        retCode = 5;
    }
    catch (FTPConnectionClosedException e)
    {
        logError("ftpFile(String, String, String, String, String)", e); //$NON-NLS-1$

        retCode = 4;
        e.printStackTrace();
    }
    catch (IOException e)
    {
        logError("ftpFile(String, String, String, String, String)", e); //$NON-NLS-1$

        e.printStackTrace();
        e.printStackTrace();
        retCode = 2;
    }
    finally
    {
        if (client.isConnected())
        {
            try
            {
                if(null != input)
                {
                    input.close();
                }
                client.disconnect();
            }
            catch (IOException f)
            {
                logWarning("ftpFile(String, String, String, String, String) - exception ignored", f); //$NON-NLS-1$
            }
        }
    }

日志文件跟踪:

2010-10-12 10:57:53,527 信息 [STDOUT] 230 成功登录
2010-10-12 10:57:53,527 信息 [STDOUT] PASV
2010-10-12 10:57:53,576 信息 [STDOUT] 227 进入被动模式 (216,27,89,17,10,231)
2010-10-12 10:57:53,624 信息 [STDOUT] STOR SharperImageFeed2.txt
2010-10-12 10:57:53,681 信息 [STDOUT] 150 "/SharperImageFeed2.txt" 文件已准备好以ASCII模式接收
2010-10-12 10:57:54,337 信息 [STDOUT] 226 传输成功完成。
2010-10-12 10:57:54,337 信息 [STDOUT] QUIT
2010-10-12 10:57:54,384 信息 [STDOUT] 221 Windows FTP服务器(WFTPD,由Texas Imperial Software提供)告别

是否有任何建议? 是否可以运行任何测试?

我可以使用FileZilla进行ftp上传文件。


进一步测试后,当我从我的本地开发环境(Windows(Eclipse / JBoss))运行时,我能够执行成功的FTP put。但是,当从生产服务器(Linux / JBoss)运行FTP时,跟踪指示它成功了,但没有将任何内容放置在FTP服务器上。

1个回答

4

我添加了上述内容,但导致该方法挂起。 - boyd4715
这对我来说可行,使用completePendingCommand上传到Linux服务器。 - Jonathan Holloway

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接