import java.lang.*;
import java.net.*;
import java.io.*;
import sun.net.*;
import sun.net.ftp.*;public class Ftp
{
FtpClient ftpClient;//--------------------------------------------------------------------------
public void upload(String filepathname)//filepathname文件名用'/'格开
{
byte[] bytes=new byte[1024];
int count;
try{
String fg = new String("/");
int index = filepathname.lastIndexOf(fg);
String filename= filepathname.substring(index + 1);
System.out.println(filepathname);
System.out.println(filename);
System.out.println("0000000000000000");
RandomAccessFile sendFile = new RandomAccessFile(filepathname, "r");
System.out.println("1111111111111");
sendFile.seek(0);
System.out.println("222222222");
TelnetOutputStream os=ftpClient.put(filename);
while((count=sendFile.read(bytes))!=-1){
os.write(bytes);
}
sendFile.close();
os.close();
System.out.println("文件上传成功!!!");
}
catch (IOException e) {
System.out.println("文件上传失败!!!");
}
}
//----------------------------------------------------------------------
public void download(String filename)
{
byte[] bytes=new byte[1024];
int count;
try{
RandomAccessFile downFile = new RandomAccessFile(filename, "rw");
downFile.seek(0);
TelnetInputStream is =ftpClient.get(filename);
while ((count=is.read(bytes)) != -1)
{
downFile.write(bytes,0,count);
}
is.close();
downFile.close();
System.out.println("文件下载成功!!!");
}
catch (IOException e) {
System.out.println("文件下载失败!!!");
}
}
public Ftp()
{
String server="192.168.1.232";
String user="administrator";
String password="1234";
String filename="d:/download/1.txt"; try{
ftpClient=new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user,password);
ftpClient.binary();
System.out.println("连接ok!");
upload(filename);
//download("1.txt");
ftpClient.closeServer();
}
catch(FtpLoginException e){
System.out.println("无权限与主机:连接!");
}
catch (IOException e){
System.out.println("连接主机失败!");
}
catch(SecurityException e)
{
System.out.println("无权限与主机:连接!");
}
}
public static void main(String[] args)
{
Ftp aftp=new Ftp();
}
}
请问在本机和在远程的机的目录结构应该是什么样的,执行到
System.out.println("0000000000000000");
RandomAccessFile sendFile = new RandomAccessFile(filepathname, "r");
System.out.println("1111111111111");
的时候就过半不去了.
import java.net.*;
import java.io.*;
import sun.net.*;
import sun.net.ftp.*;public class Ftp
{
FtpClient ftpClient;//--------------------------------------------------------------------------
public void upload(String filepathname)//filepathname文件名用'/'格开
{
byte[] bytes=new byte[1024];
int count;
try{
String fg = new String("/");
int index = filepathname.lastIndexOf(fg);
String filename= filepathname.substring(index + 1);
System.out.println(filepathname);
System.out.println(filename);
System.out.println("0000000000000000");
RandomAccessFile sendFile = new RandomAccessFile(filepathname, "r");
System.out.println("1111111111111");
sendFile.seek(0);
System.out.println("222222222");
TelnetOutputStream os=ftpClient.put(filename);
while((count=sendFile.read(bytes))!=-1){
os.write(bytes);
}
sendFile.close();
os.close();
System.out.println("文件上传成功!!!");
}
catch (IOException e) {
System.out.println("文件上传失败!!!");
}
}
//----------------------------------------------------------------------
public void download(String filename)
{
byte[] bytes=new byte[1024];
int count;
try{
RandomAccessFile downFile = new RandomAccessFile(filename, "rw");
downFile.seek(0);
TelnetInputStream is =ftpClient.get(filename);
while ((count=is.read(bytes)) != -1)
{
downFile.write(bytes,0,count);
}
is.close();
downFile.close();
System.out.println("文件下载成功!!!");
}
catch (IOException e) {
System.out.println("文件下载失败!!!");
}
}
public Ftp()
{
String server="192.168.1.232";
String user="administrator";
String password="1234";
String filename="d:/download/1.txt"; try{
ftpClient=new FtpClient();
ftpClient.openServer(server);
ftpClient.login(user,password);
ftpClient.binary();
System.out.println("连接ok!");
upload(filename);
//download("1.txt");
ftpClient.closeServer();
}
catch(FtpLoginException e){
System.out.println("无权限与主机:连接!");
}
catch (IOException e){
System.out.println("连接主机失败!");
}
catch(SecurityException e)
{
System.out.println("无权限与主机:连接!");
}
}
public static void main(String[] args)
{
Ftp aftp=new Ftp();
}
}
请问在本机和在远程的机的目录结构应该是什么样的,执行到
System.out.println("0000000000000000");
RandomAccessFile sendFile = new RandomAccessFile(filepathname, "r");
System.out.println("1111111111111");
的时候就过半不去了.
TelnetOutputStream os=ftpClient.put(filename);这句话错误了.