【问题标题】:Ftp Upload a folder from sdcard to ftp AndroidFtp 将文件夹从 sdcard 上传到 ftp Android
【发布时间】:2012-07-06 20:25:54
【问题描述】:

大家好,任何 java 极客都可以帮助我吗?我需要将带有 subs 文件夹的文件夹上传到我的 ftp。 我找到了一些示例代码,但仅适用于单个文件。 而且我不知道如何更改它以上传文件夹。我使用谷歌但没有找到anwser。

        String server = "192.168.1.2";
    String username = "test";
    String password = "test";
    String local = "mnt/sdcard/shopinglist/"; #This path i need to upload

    FTPClient ftp = new FTPClient();
  try
  {
      System.out.println( "Connecting" );
      ftp.connect(server);
      if(!ftp.login(username, password))
      {
          System.out.println( "Login failed" );
          ftp.logout();
          return;
      }
      int reply = ftp.getReplyCode();
      System.out.println( "Connect returned: " + reply );
      if (!FTPReply.isPositiveCompletion(reply)) {
          ftp.disconnect();
          System.out.println( "Connection failed" );
          return;
      }
      ftp.enterLocalPassiveMode(); 
      FileInputStream in = new FileInputStream(local);
      ftp.setFileType(ftp.BINARY_FILE_TYPE);
      System.out.println( "Uploading File" );
      boolean store = ftp.storeFile("mnt/sdcard/shopinglist/",in); # ??? Any help ???
      in.close();
      ftp.logout();
      ftp.disconnect();
  }
  catch(Exception ex)
  {
      ex.printStackTrace();
  }
}

}

谢谢大家。

【问题讨论】:

  • push ...任何人都可以请帮助
  • 2 天没有消息 -.- ° 这真的很难吗?我在 android java dev 中很新,但我们只需要列出文件夹中的项目并将其上传文件。任何 idee geeks dev ?

标签: android apache upload ftp


【解决方案1】:

如果有帮助,请检查下面的代码

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

如果有帮助请告诉我

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-08-21
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多