PTT
Submit
Submit
选择语言
正體中文
简体中文
PTT
AndroidDev
[问题] 在FTP下载档案~失败了?找不到PORT号?
楼主:
iori9100
(呵呵)
2017-08-02 23:33:01
这个方法也是我参考某些前辈来修改的~
但只要执行下载
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:[email protected]: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]));
}
}
作者:
cf1064
(蚵仔)
2017-08-03 00:54:00
在. connect之前,params[0]有值?
作者:
lovelycateye
(我还想要更多力量)
2017-08-03 11:50:00
你手机是用4G连还是跟你电脑同个WiFi?那看起来是内网IP,先确认你是连到跟电脑相同WiFi吧
楼主:
iori9100
(呵呵)
2017-08-03 17:56:00
给上面前辈,我是用模拟器的,网络应该是在同网域,另外param[0]得到的值是 执行方法宣告的网址
作者:
ssccg
(23)
2017-08-03 18:09:00
用实机试试看
作者:
lovelycateye
(我还想要更多力量)
2017-08-04 00:42:00
我用 Unable to configure data port 还不少啊第一个结果的你确定有试过?
https://goo.gl/nTxU3w
楼主:
iori9100
(呵呵)
2017-08-04 13:17:00
其实下载档案OK 但我是不知道怎么把过程丢给进度条..@@类似用上面那个网址 先把PORT号那些参数都设定好就可以
继续阅读
[问题] Firebase Authentication + Unity
BF109Pilot
[问题] 阵列传递的方法
sologe
[问题] 请问直接用FFmpeg能直接推流吗?
rul3nk41
[问题] 使用FB登入后如何显示资料
chingyue
[问题] UDP in Service
areyo
[问题] 多个Activity切换时 不onDestroy
gcobc12632
[问题] 从耳机孔取得 raw PCM 讯号
kaltu
[问题] okhttp取得压缩后json资料问题
axalto
[问题] Android TV WebView 按键没有回应
winsummer
[问题] 多个按钮存入button array
pig98520
Links
booklink
Contact Us: admin [ a t ] ucptt.com