[問題] 在FTP下載檔案~失敗了?找不到PORT號?
這個方法也是我參考某些前輩來修改的~
但只要執行下載
java.io.IOException: Unable to connect to server: Unable to configure data
port
at libcore.net.url.FtpURLConnection.connect(FtpURLConnection.java:203)
at
com.example.user.ftpupload.MainActivity$DownloadTask.
doInBackground(MainActivity.java:172)
connection.connect();這行會掛 可是我查了相關的實作~
我在URL那邊的網址字串是可以的 但一直連不進去~
請問有大大可以指正我一下嗎? 因為查了不少文章 都是跟HTTP的範例有關的
還是我FTP寫的網址是錯誤的呢?? 感恩
private void StartDownload(){
String url="ftp://user:pass@192.168.1.106:21/spanish.pdf";
new DownloadTask().execute(url);
}
@Override
@Deprecated
protected Dialog onCreateDialog(int id){
switch (id){
case DIALOG_DOWNLOAD_PROGRESS:
mProgressDialog = new ProgressDialog(this);
mProgressDialog.setMessage("Downloading...");
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
mProgressDialog.setCancelable(true);
mProgressDialog.show();
return mProgressDialog;
default:
return null;
}
}
class DownloadTask extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
showDialog(DIALOG_DOWNLOAD_PROGRESS);
}
@Override
protected String doInBackground(String... params) {
int count;
try {
URL url= new URL(params[0]);
URLConnection connection = url.openConnection();
@@@@@@@@@@@@@@@ connection.connect();掛在這行@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
int filelength=connection.getContentLength();
Log.d("長度", "doInBackground: "+filelength);
InputStream input= new BufferedInputStream(url.openStream());
OutputStream output= new
FileOutputStream(android.os.Environment.getExternalStorageDirectory().getAbsolutePath()+"/Download/lesson");
byte data[]= new byte[1024];
int total=0;
while((count=input.read(data))!=-1) {
total += count;
publishProgress("" + (int) ((total * 100) / filelength));
output.write(data, 0, count);
}
output.flush();
output.close();
input.close();
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String result) {
dismissDialog(DIALOG_DOWNLOAD_PROGRESS);
}
@Override
protected void onProgressUpdate(String... values) {
Log.d("HEHEHEHE", values[0]);
mProgressDialog.setProgress(Integer.parseInt(values[0]));
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 1.163.99.157
※ 文章網址: https://www.ptt.cc/bbs/AndroidDev/M.1501687984.A.F56.html
→
08/03 00:54, , 1F
08/03 00:54, 1F
→
08/03 11:50, , 2F
08/03 11:50, 2F
→
08/03 11:50, , 3F
08/03 11:50, 3F
→
08/03 17:56, , 4F
08/03 17:56, 4F
→
08/03 17:56, , 5F
08/03 17:56, 5F
→
08/03 18:09, , 6F
08/03 18:09, 6F
→
08/04 00:42, , 7F
08/04 00:42, 7F
→
08/04 00:42, , 8F
08/04 00:42, 8F
→
08/04 13:17, , 9F
08/04 13:17, 9F
→
08/04 13:18, , 10F
08/04 13:18, 10F
AndroidDev 近期熱門文章
PTT數位生活區 即時熱門文章