请问:在Java中怎样实现ftp

来源:百度知道 编辑:UC知道 时间:2024/05/19 21:26:54
我是这个方面的菜鸟,请指点

使用ftpClient类

ftpClient的文件路径是相对路径还是绝对路径和Ftp Server的类型有关,我就遇到过wu-ftp是相对路径而vs-ftp是绝对路径的问题,所以你最好在put文件的时候不要用/xxx/xxx这种绝对路径的书写方式。还有ftp用户权限问题,linux下root不能作为ftp用户的所以通常用的用户不一定能够在你的目的路径下有写文件的权限,所以一定要建好目录再传。这个没有什么实际例子,我用的也是网上的例子。
public boolean sendFile(String filepathname, String distfilepathname) {
boolean result = true;
if (aftp != null) {
System.out.println("正在粘贴文件,请耐心等待....");

String contentperline;
try {
a = "粘贴成功!";
String fg = new String("/");
int index = filepathname.lastIndexOf(fg);
String filename = filepathname.substring(index + 1);
File localFile;
localFile = new File(filepathname);
RandomAccessFile sendFile = new RandomAccessFile(filepathname, "r");
//
sendFile.seek(0);
outs = aftp.put(distfilepathname);
outputs = new DataOutpu