奇怪的问题,而从Android的文件发送到服务器!

问题描述 投票:0回答:1

在发送文件,如通过ftp的图片,文字和zip文件服务器我遇到了一个很奇怪的问题。在大多数情况下,它工作正常。但有时,服务器只有文件的一部分。在Android上,我用com.enterprisedt.net.ftp。下面是一段代码发送一个文件:

public void ftpUploadFiles(ArrayList<String> fileList, boolean bDeleteAfterUploaded)
{
    if(fileList.size() <= 0)
        return;

    // set up to transfer the files
    FileTransferClient ftp = null;
    try 
    {
        //Make sure there is only FTP in the whole system at any given time.
        synchronized(this)
        {
            // create client
            ftp = new FileTransferClient();
            // set remote host
            ftp.setRemoteHost("xxxxxxx");

            ftp.setUserName("xxxxxx");
            ftp.setPassword("xxxxx");

            // connect to the server
            ftp.connect();
            ftp.getAdvancedFTPSettings().setConnectMode(FTPConnectMode.PASV);
            //1. Upload each file
            for(int i = 0 ; i < fileList.size(); i++)
            {
                if(!FileKit.fileExist(fileList.get(i)))
                    continue;

                ftp.uploadFile(fileList.get(i), FileKit.getFileName(fileList.get(i)));

                if(bDeleteAfterUploaded)
                    FileKit.fileDelete(fileList.get(i));
            }

            ftp.disconnect();
        } //End of synchronized
    } catch (Exception e) 
    {
        FileKit.handleException(e);
    }
}

FileKit是常规文件功能的静态总结类。 ftpUploadFiles()由一个Intent称为在单独的线程,因此它可以在后台运行。有什么事发生的是,在FTP完全传输文件之前完成停止,所以服务器只获取文件的一部分。基于上面的代码,什么可能导致此问题?或者是有可能是与com.enterprisedt.net.ftp一个问题?

谢谢。

android file ftp send
1个回答
0
投票

您的代码似乎只处理完整的文件。因此,它应该成功或失败的唯一完整的文件。这使得只有com.enterprisedt.net.ftp包,当网络发生故障时可以在部件发送文件,例如。

可以有一个问题,如果传送由于网络拥塞,等等。“如果网络连接中断,该服务器仍然可以认为你是连接(如退出()没有被调用)。因此,一个新的连接,并试图中断恢复可能会失败,下面给出的理由“。 (https://enterprisedt.com/forums/viewtopic.php?t=960

所以我认为,无论是FTP软件对网络故障的错误,或者你的代码不处理网络故障的FTP软件的处理。

© www.soinside.com 2019 - 2024. All rights reserved.