ftp实现


import sun.net.ftp.FtpClient;
import java.io.*;
import sun.net.*;

public class ftpDown
{
public ftpDown()
{
}
public static void main(String[] args)
{
try
{
FtpClient fc=new FtpClient("ip");
fc.login("root","***");
int ch;
File fi = new File("**");
RandomAccessFile getFile = new RandomAccessFile(fi,"rw");
getFile.seek(0);
TelnetInputStream fget=fc.get("远程文件名");
DataInputStream puts = new DataInputStream(fget);
while ((ch = puts.read()) >= 0) {
getFile.write(ch);
}
fget.close();
getFile.close();
fc.closeServer();
}
catch (IOException ex)
{
ex.printStackTrace();
}
}
}

我是下载unix是的东东。。。
java ftpDown出错。。。
---------- java ----------
sun.net.TelnetProtocolException: misplaced CR in input
at sun.net.TelnetInputStream.read(TelnetInputStream.java:93)
at java.io.FilterInputStream.read(FilterInputStream.java:66)
at ftpDown.main(ftpDown.java:22)
Normal Termination
输出完成(耗时 0 秒)。


fc.binary();

你可能感兴趣的:(ftp)