当我尝试使用来自 android 的 ftp 客户端从 drivehq ftp 服务器获取目录列表时,出现连接被拒绝异常。请帮助我并解决我的问题。下面给出了我为此目的的代码,我也在真实设备三星银河手机上进行测试。是的,我已经添加了这些权限
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
public void login(String host,String username,String password,int port)
{
try
{
ftpClient.connect(host);
ftpClient.login(username, password);
ftpClient.changeWorkingDirectory("/MyData");
ftpClient.setFileType(FTP.BINARY_FILE_TYPE);
ftpClient.enterLocalPassiveMode();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public ArrayList<File> getDirectoryListing()
{
ArrayList<File> list=new ArrayList<File>();
FTPFile[] files = null;
try
{
Log.d(ftpClient.printWorkingDirectory(), "is working directory");
files=ftpClient.listFiles();
for(FTPFile f:files)
{
String s=f.getName();
Log.d(s, "is file");
File fs=new File(s);
list.add(fs);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}