下面是创建一个文本文档并上传到FTP服务器的代码。但不知何故它似乎无法工作。我使用了提供在以下链接中的库与FTP服务器进行通信:http://lavalatwork.blogspot.tw/2010/09/using-apache-commons-ftp-library-in.html。
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();
}
任何帮助都将不胜感激。