如何下载FTP服务器上的.txt文件 [英] How to download a .txt file from ftp server
本文介绍了如何下载FTP服务器上的.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要一个.txt格式的文件来回回我的服务器下载到我的Android机。但我不知道如何从服务器下载一个文件,其中包含的用户名和密码来下载文件。没有任何一个帮助我了点。我是新到Android编程。
I have to download a .txt format file fro my server to my android machine. But i don't know how to download a file from server which contains username as well as password to download file. Does any one help me for that. I am new to android programming.
推荐答案
查找共享网库阿帕奇 - 的 http://commons.apache.org/proper/commons-net/ 。它提供了与FTP工作的工具。
Look for commons net apache library - http://commons.apache.org/proper/commons-net/. It provides a tools for work with FTP.
code例如
FileOutputStream videoOut;
File targetFile = new File("path");
FTPClient ftpClient = new FTPClient();
try {
ftpClient.connect("your.ftp.address", 21);
ftpClient.enterLocalPassiveMode();
ftpClient.login("login", "password");
ftpClient.setFileType(FTPClient.BINARY_FILE_TYPE);// Used for video
targetFile.createNewFile();
videoOut = new FileOutputStream(targetFile);
boolean result=ftpClient.retrieveFile("/" + "filename-to-download", videoOut);
ftpClient.disconnect();
videoOut.close();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e){
e.printStackTrace();
}
这篇关于如何下载FTP服务器上的.txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文