【问题标题】:How can I upload a whole folder to a server in android如何将整个文件夹上传到android中的服务器
【发布时间】:2014-04-10 18:27:23
【问题描述】:

我在安卓设备上有一个文件夹,我想上传到我的服务器。

在服务器端使用 PHP。

它可以是 FTP 或任何其他选项..

(哦,我必须在服务中完成)..

【问题讨论】:

    标签: android upload ftp android-service httprequest


    【解决方案1】:
    USE THIS :
    
    public void goforIt(){
    
    
        FTPClient con = null;
    
        try
        {
            con = new FTPClient();
            con.connect("192.168.2.57"); //Your server IP
    
            if (con.login("Administrator", "KUjWbk")) //Your Login Creadentials
            {
                con.enterLocalPassiveMode(); // important!
                con.setFileType(FTP.BINARY_FILE_TYPE);
                String data = "/sdcard/vivekm4a.m4a";    
    
                FileInputStream in = new FileInputStream(new File(data));
                boolean result = con.storeFile("/vivekm4a.m4a", in);
                in.close();
                if (result) Log.v("upload result", "succeeded");
                con.logout();
                con.disconnect();
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    

    【讨论】:

    • 但它是一个文件夹..在这段代码中你正在上传一个文件../sdcard/vivekm4a.m4a..
    【解决方案2】:

    是的,你是对的。

    好的文件夹试试这个:

    Intent intent = new Intent();
    intent.setAction(Intent.ACTION_PICK);
    // FTP URL (Starts with ftp://, sftp:// or ftps:// followed by hostname and port).
    Uri ftpUri = Uri.parse("ftp://yourftpserver.com");
    intent.setDataAndType(ftpUri, "vnd.android.cursor.dir/lysesoft.andftp.uri");
    // FTP credentials (optional)
    intent.putExtra("ftp_username", "anonymous");
    intent.putExtra("ftp_password", "something@somewhere.com");
    //intent.putExtra("ftp_keyfile", "/sdcard/dsakey.txt");
    //intent.putExtra("ftp_keypass", "optionalkeypassword");
    // FTP settings (optional)
    intent.putExtra("ftp_pasv", "true");
    //intent.putExtra("ftp_resume", "true");
    //intent.putExtra("ftp_encoding", "UTF8");
    // Upload
    intent.putExtra("command_type", "upload");
    // Activity title
    intent.putExtra("progress_title", "Uploading folder ...");
    intent.putExtra("local_file1", "/sdcard/localfolder");
    // Optional initial remote folder (it must exist before upload)
    intent.putExtra("remote_folder", "remotefolder/uploadedfolder");
    startActivityForResult(intent, 2);
    

    【讨论】:

    • 好吧..我怎样才能有意图地做到这一点? (我必须在服务内完成)
    猜你喜欢
    • 2016-03-20
    • 2019-12-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多