如题,使用的是apache的net类库,FTPClient,贴代码:public static void main(String[] args) throws IOException {
FTPClient ftp = new FTPClient();
int reply;
ftp.connect("***.***.***.***");
ftp.login("***", "***");
System.out.println(ftp.getReplyString());
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
InputStream is = new FileInputStream("d:/1/2/4.txt");
OutputStream os = ftp.storeFileStream("/home/test/4.txt");
byte[] buffer = new byte[1024];
int len;
while((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
is.close();
os.close();
ftp.logout();
if(ftp.isConnected()) {
ftp.disconnect();
}
}连接是没有问题的,可以登录成功,但是storeFileStream得到的os却是null的,求助。
FTPClient ftp = new FTPClient();
int reply;
ftp.connect("***.***.***.***");
ftp.login("***", "***");
System.out.println(ftp.getReplyString());
reply = ftp.getReplyCode();
if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
InputStream is = new FileInputStream("d:/1/2/4.txt");
OutputStream os = ftp.storeFileStream("/home/test/4.txt");
byte[] buffer = new byte[1024];
int len;
while((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
is.close();
os.close();
ftp.logout();
if(ftp.isConnected()) {
ftp.disconnect();
}
}连接是没有问题的,可以登录成功,但是storeFileStream得到的os却是null的,求助。
解决方案 »
- 将一个元素插入到数组的指定位置中
- 请教ajax的问题
- 下面的程序程序哪个方法体先执行?m1还是m2?高手分析一下好吗?进来看看
- 简单的“需要 <标识符>”错误求救
- 正则表达式 regex pattern
- does anyone can help me about EditPlus
- Calendar set方法,有时候不会主动刷新,真奇怪,必须调用get之类的方法
- 在线等~~请问各位大虾:如何从字符改为整数???
- 紧急求助:怎么把数据库里面的时间字段提取出来后与当前时间比较。。。。。。。。。。。
- 一个简单的问题,请大家帮忙
- 关于鼠标监听器的问题:在mouseRealeased方法中添加PopupMenu的显示后,出现的奇怪问题
- 谁有好的随机子数组函数
如果客户端方面存在NAT(PAT)之类的转换,还要注意使用被动模式(都是外网IP则使用主动模式)传输数据。那些个返回上一个命令处理结果的方法,有时候会被FTPClient对象中的某个方法调用过,
我记得,这些方法,貌似不能重复调用的。楼主可以尝试:
1。查看login方法是否已经带有返回值,如果有,则直接根据返回值进行判断。
2.删掉查询登陆结果的代码试试,也许问题就出在这里。
FTPClient ftp = new FTPClient();
int reply;
ftp.connect("***.***.***.***");
if (!ftp.login("***", "***")) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
System.exit(1);
}
InputStream is = new FileInputStream("d:/1/2/4.txt");
OutputStream os = ftp.storeFileStream("/home/test/4.txt");
byte[] buffer = new byte[1024];
int len;
while((len = is.read(buffer)) != -1) {
os.write(buffer, 0, len);
}
is.close();
os.close();
ftp.logout();
if(ftp.isConnected()) {
ftp.disconnect();
}
}
FTP还有一个比较麻烦的问题是“相对路径”和“绝对路径”在编程中,选哪种来用。
反正,我都选绝对路径,虽然,每次都要拼接地址,但是,排错较容易些。
而且是不存在的时候创建吧。