📄 例10-10.java
字号:
//例10.10 FTPClass.java
import sun.net.ftp.*;
import sun.net.*;
import java.net.*;
import java.io.*;
class FTPClass
{
static FtpClient Ftp;
public static void main(String args[]) throws Exception
{
StringBuffer buf=new StringBuffer();
Ftp=new FtpClient(args[0]);
Ftp.login("anonymus","XX@263.net");
Ftp.ascii();
TelnetInputStream input=Ftp.list();
System.out.println("The content(directories and files)and files)of remote host:");
int ch;
while((ch=input.read())>=0)
buf.append((char)ch);
input.close();
System.out.println(buf.toString());
System. out.println();
System.out.println("pliase input the filename you want to download;");
buf.setLength(0);
try
{
while((ch=(char)System.in.read())!='\n')
buf.append((char)ch);
}
catch(IOException e)
{ System.out.println("Caught exception:"+e. getMessage()); }
input.close();
System.out.println("The content of the downIoad file:");
System.out.println(buf.toString());
System.out.println();
System.out.println("PIease input the file name and ditectory name of sending toremote host");
System.out.print("File name:");
buf.setLength(0);
try
{
while((ch=(char)System.in.read())!='\n')
buf.append((char)ch);
}
catch(IOException e)
{ System.out.println("cayggt excwption:"+e. getMessage()); }
StringBuffer dir=new StringBuffer();
System.out.print("\nDirectory name:");
try
{
while((ch=(char)System.in.read())!='\n')
dir.append((char)ch);
}
catch(IOException e)
{
System.out.println("exception:"+e.getMessage());
File localFile=new File(dir.toString(),buf.toString());
RandomAccessFile sendFile=new RandomAccessFile(localFile,"rw");
TelnetOutputStream output=Ftp.put(buf.toString());
sendFile.seek(0);
while(sendFile.getFilePointer()<sendFile.length())
{
ch=sendFile.read();
output.write(ch);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -