<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>一起去看海 &#187; FTP</title>
	<atom:link href="http://www.ooobj.com/tag/ftp/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ooobj.com</link>
	<description>ooobj.com</description>
	<lastBuildDate>Sat, 14 Jan 2012 13:48:28 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>JAVA连接FTP测试</title>
		<link>http://www.ooobj.com/2010/05/java-ftp/</link>
		<comments>http://www.ooobj.com/2010/05/java-ftp/#comments</comments>
		<pubDate>Tue, 04 May 2010 03:04:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Java笔记]]></category>
		<category><![CDATA[FTP]]></category>

		<guid isPermaLink="false">http://www.ooobj.com/?p=26375</guid>
		<description><![CDATA[毕设中要连接FTP，于是找了一下JAVA连接ftp的方法。发现有两个比较常用的包，一个是JDK自带的sun.net.ftp，功能比较简单。一个是org.apache.commons.net.ftp。这里先用sun.net.ftp写个Demo。
[java]package com.ooobj.test;
import java.io.DataInputStream;
import java.io.IOException;
import sun.net.ftp.FtpClient;
public class FTPTest {
 public static void main(String[] args) {
 try {
 FtpClient fc = new FtpClient(&#34;192.168.7.128&#34;, 21);
 fc.login(&#34;ooobj&#34;, &#34;123&#34;);
 System.out.println(fc.pwd());
 DataInputStream dis = new DataInputStream(fc.nameList(&#34;.&#34;));
 String s = &#34;&#34;;
 while ((s = dis.readLine()) != null) {
 System.out.println(new String(s.getBytes(&#34;ISO-8859-1&#34;),&#34;GBK&#34;));
 }
 } catch (IOException e) {
 e.printStackTrace();
 }
 }
}[/java]
其中nameList()方法是列出文件，不包括文件夹。list()方法则列出文件和文件夹。sun.net.ftp提供的字符编码是&#8221;ISO-8859-1&#8243;，需要在读取的时候转换，比较麻烦。
]]></description>
			<content:encoded><![CDATA[<p>毕设中要连接FTP，于是找了一下JAVA连接ftp的方法。发现有两个比较常用的包，一个是JDK自带的sun.net.ftp，功能比较简单。一个是org.apache.commons.net.ftp。这里先用sun.net.ftp写个Demo。</p>
<p>[java]package com.ooobj.test;</p>
<p>import java.io.DataInputStream;<br />
import java.io.IOException;</p>
<p>import sun.net.ftp.FtpClient;</p>
<p>public class FTPTest {</p>
<p> public static void main(String[] args) {<br />
 try {<br />
 FtpClient fc = new FtpClient(&quot;192.168.7.128&quot;, 21);<br />
 fc.login(&quot;ooobj&quot;, &quot;123&quot;);<br />
 System.out.println(fc.pwd());<br />
 DataInputStream dis = new DataInputStream(fc.nameList(&quot;.&quot;));<br />
 String s = &quot;&quot;;<br />
 while ((s = dis.readLine()) != null) {<br />
 System.out.println(new String(s.getBytes(&quot;ISO-8859-1&quot;),&quot;GBK&quot;));<br />
 }<br />
 } catch (IOException e) {<br />
 e.printStackTrace();<br />
 }</p>
<p> }</p>
<p>}[/java]</p>
<p>其中nameList()方法是列出文件，不包括文件夹。list()方法则列出文件和文件夹。sun.net.ftp提供的字符编码是&#8221;ISO-8859-1&#8243;，需要在读取的时候转换，比较麻烦。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ooobj.com/2010/05/java-ftp/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

