是的,所以我使用的是这段代码,但每当我运行它时,它都不会上传任何内容。我在另一个程序中有类似的代码,完美的作品。我错过了什么?
public void upload(){
new Thread(new Runnable() {
public void run() {
if (Looper.myLooper() == null)
{
Looper.prepare();
}
FTPClient ftpClient = new FTPClient();
FileInputStream inputStream = null;
int Upload = sharedPreferences.getInt("Upload", 1);
if (Upload == 1) {
try {
ftpClient.connect(InetAddress.getByName("XXX.net"));
ftpClient.login("XXX", "XXX");
ftpClient.changeWorkingDirectory("/public_html/Images/Cross");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE, FTP.BINARY_FILE_TYPE);
File file = new File(getApplicationInfo().dataDir + "/files/" + "temp" + ".jpg");
inputStream = new FileInputStream(file);
ftpClient.storeFile("temporary.jpg", inputStream);
file.delete();
ftpClient.logout();
ftpClient.disconnect();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
...
}