有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java commons网络ftp问题

我面临的问题是,我的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 INFO [STDOUT] 230 Logged in successfully
2010-10-12 10:57:53,527 INFO [STDOUT] PASV
2010-10-12 10:57:53,576 INFO [STDOUT] 227 Entering Passive Mode (216,27,89,17,10,231)
2010-10-12 10:57:53,624 INFO [STDOUT] STOR SharperImageFeed2.txt
2010-10-12 10:57:53,681 INFO [STDOUT] 150 "/SharperImageFeed2.txt" file ready to receive in ASCII mode
2010-10-12 10:57:54,337 INFO [STDOUT] 226 Transfer finished successfully.
2010-10-12 10:57:54,337 INFO [STDOUT] QUIT
2010-10-12 10:57:54,384 INFO [STDOUT] 221 Windows FTP Server (WFTPD, by Texas Imperial Software) says goodbye

关于这个问题有什么建议吗?有可以运行的测试吗

我可以使用FileZilla通过ftp上传文件


通过进一步测试,当我从本地dev env(即Windows(Eclipse/JBoss))运行FTP时,我能够成功地执行FTP put,但当从生产服务器(Linux/JBoss)运行FTP时,跟踪表明它成功,但FTP服务器上没有放置任何内容


共 (1) 个答案