我在这里搜索了这个主题,我尝试了所有我找到的,但它仍然不起作用。
import java.io.FileInputStream;
import java.io.IOException;
import org.apache.commons.net.ftp.FTPClient;
import android.os.Bundle;
import android.os.Environment;
import android.app.Activity;
public class MainActivity extends Activity {
public static final String TAG = "Contacts";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
我做了一个线程,因为它不允许在主线程上运行;
Thread t = new Thread(new Runnable(){
@Override
public void run(){
Versuch();
}
});
t.start();
}
在这里,我尝试上传数据,但在 Log Cat 中没有显示错误。
public void Versuch(){
FTPClient client = new FTPClient();
FileInputStream fis = null;
try {
client.connect("ftp-web.example");
client.login("ftpuser", "ftppassword");
String filename = Environment.getExternalStorageDirectory().getAbsolutePath() + "/DCIM";
fis = new FileInputStream(filename);
// Store file to server
//
client.storeFile(filename, fis);
client.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
client.disconnect();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}