谢谢,回复。不过我想问的是,如果我要获取LINUX上的某个路径下的文件呢。该如何处理 FtpClient fc=new FtpClient("ftp.xx.com");//linux机器地址 fc.login("username","888888");//用户名 int ch; File fi = new File("c:\\index.html");//这个该如何写? RandomAccessFile getFile = new RandomAccessFile(fi,"rw"); getFile.seek(0); TelnetInputStream fget=fc.get("index.html");//这个和上面的index.html又有什么关系啊
FTPClient基本上合FTP命令行的用法一样 比方说 get /var/temp/some.text 这个命令,你可以直接sendCommand FTP命令行的时候,可以用cd/lcd之类的命令设置本地和远端工作的当前目录,一般FTPClient会对此做封装,你也可以用这些接口你new的file和fc.get的file,没啥关系。 FTPClient会自己处理文件打开关闭的事情。要说有关系,就是,如果你们的文件绝对路径刚好相等的话,可能会出异常
import java.io.*;
import sun.net.*;/**
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: </p>
* @author petehero
* @version 1.0
*/public class ftpDown
{ public ftpDown()
{ }
public static void main(String[] args)
{
try
{
FtpClient fc=new FtpClient("ftp.xx.com");
fc.login("username","888888");
int ch;
File fi = new File("c:\\index.html");
RandomAccessFile getFile = new RandomAccessFile(fi,"rw");
getFile.seek(0);
TelnetInputStream fget=fc.get("index.html");
DataInputStream puts = new DataInputStream(fget);
while ((ch = puts.read()) >= 0) {
getFile.write(ch);
}
fget.close();
getFile.close();
fc.closeServer();
}
catch (IOException ex)
{ ex.printStackTrace();
} }
}这个,不算第三方的吧............
linux端的文件服务很多,FTP/SFTP最常见。
基本上文件传输都是个 C/S 模式的活,你总是要有意无意的使用第三方包,如果说完全自己写代码,那就需要在linux上跑一个你的程序,在windows上跑一个你的程序。
真正的文件下载、上传比较复杂,需要考虑网络环境,带宽,重传,安全等等问题,你的问题在哪个范围内呢?
FtpClient fc=new FtpClient("ftp.xx.com");//linux机器地址
fc.login("username","888888");//用户名
int ch;
File fi = new File("c:\\index.html");//这个该如何写?
RandomAccessFile getFile = new RandomAccessFile(fi,"rw");
getFile.seek(0);
TelnetInputStream fget=fc.get("index.html");//这个和上面的index.html又有什么关系啊
比方说 get /var/temp/some.text 这个命令,你可以直接sendCommand
FTP命令行的时候,可以用cd/lcd之类的命令设置本地和远端工作的当前目录,一般FTPClient会对此做封装,你也可以用这些接口你new的file和fc.get的file,没啥关系。 FTPClient会自己处理文件打开关闭的事情。要说有关系,就是,如果你们的文件绝对路径刚好相等的话,可能会出异常