我在Android设备上有一个文件夹,我希望将其上传到我的服务器。
在服务器端使用PHP。
它可以是FTP或任何其他选项..
(哦,我必须在服务中做到这一点)..
答案 0 :(得分:0)
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();
}
答案 1 :(得分:0)
是的,你是对的。
好的文件夹试试这个:
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);