【发布时间】:2012-07-21 00:10:47
【问题描述】:
以下是用于创建文本文档并将其上传到我的 FTP 服务器的代码。由于某种原因,它似乎不起作用。我习惯了
提供的库http://lavalatwork.blogspot.tw/2010/09/using-apache-commons-ftp-library-in.html
用于与 FTP 服务器通信。
try
{
final String testString = new String("Hello");
FileOutputStream fOut = openFileOutput("samplefile.txt",
MODE_WORLD_READABLE);
OutputStreamWriter osw = new OutputStreamWriter(fOut);
osw.write(testString);
osw.flush();
osw.close();
}
catch(IOException ex)
{
}
FTPClient mFTP = new FTPClient();
try {
// Connect to FTP Server
mFTP.connect("192.168.10.101");
//mFTP.login("user", "password");
mFTP.setFileType(FTP.BINARY_FILE_TYPE);
mFTP.enterLocalPassiveMode();
// Prepare file to be uploaded to FTP Server
File file = new File(getFileStreamPath("samplefile.txt")+ "");
FileInputStream ifile = new FileInputStream(file);
// Upload file to FTP Server
mFTP.storeFile("filetotranfer",ifile);
mFTP.disconnect();
} catch (SocketException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
任何帮助将不胜感激。
【问题讨论】:
-
在使用 Apache Commons FTP 客户端时检查 logcat 的输出通常很有帮助。
-
请明确说明什么是行不通的。并发布您的 logcat。
标签: java android ftp apache-commons apache-commons-net