请高手赐教!很急!
本段程序是实现按照本地机器上的一个文件夹目录结构传送到FTP服务器上的功能,为了简化方便高手的解答我只传送一层,多层跟这个一样的问题!下面程序中一个是判断文件和文件夹的,两个相互分开时,可以运行,但放在一起会出错!
错误信息:
java.io.FileNotFoundException: CWD /2: 550 /2/???¨??????: Failed to create.
at sun.net.ftp.FtpClient.readReply(Unknown Source)
at sun.net.ftp.FtpClient.issueCommand(Unknown Source)
at sun.net.ftp.FtpClient.issueCommandCheck(Unknown Source)
at sun.net.ftp.FtpClient.cd(Unknown Source)
at shareit.ftp.FtpConnection.run(FTPtxt.java:110)
sun.net.ftp.FtpProtocolException: PORT :500 'EPRT ': command not understood.
at sun.net.ftp.FtpClient.openDataConnection(Unknown Source)
at sun.net.ftp.FtpClient.put(Unknown Source)
at shareit.ftp.FtpConnection.run(FTPtxt.java:118)
sun.net.ftp.FtpProtocolException: PORT :500 'EPRT ': command not understood.
at sun.net.ftp.FtpClient.openDataConnection(Unknown Source)
at sun.net.ftp.FtpClient.put(Unknown Source)
at shareit.ftp.FtpConnection.run(FTPtxt.java:118)
sun.net.ftp.FtpProtocolException: PORT :500 'EPRT ': command not understood.
at sun.net.ftp.FtpClient.openDataConnection(Unknown Source)
at sun.net.ftp.FtpClient.put(Unknown Source)
at shareit.ftp.FtpConnection.run(FTPtxt.java:118)
源程序是:
package shareit.ftp;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import sun.net.TelnetOutputStream;
import sun.net.ftp.FtpClient;
class Node
{
File[] fle;
}
class FtpConnection extends Thread
{ //private String user;
//private String password;
private FtpClient ftpclient;
FtpConnection()
{
try{ftpclient=new FtpClient( "192.168.0.66 ",21);
Login();
}
catch(Exception e){}
}
public void Login()
{
try {
ftpclient.login( "winterzd ", "2251780 ");
} catch (IOException e) {
e.printStackTrace();
}
}
public void Logout()
{
ftpclient.sendServer( "QUIT\r\n ");
int reply = 0;
try {
reply = ftpclient.readServerResponse();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println(reply);
}
public void run()
{
try {
//readirt();
//*********************************************
File file=new File( "D:\\2 ");
File[] filelist=file.listFiles();
int count=filelist.length;
System.out.println(count);
int i=count-1;
while(i> =0)
{
if(filelist[i].isDirectory()==false)
/*{try{
String path=filelist[i].getAbsolutePath();
String[] pathsplit=path.split( "\\\\ ");
int j=pathsplit.length-1;
int m=1;
String pathafter= "/ ";
while(m <=j)
{
if(m <j)pathafter=pathafter.concat(pathsplit[m])+ "/ ";
else pathafter=pathafter.concat(pathsplit[m]);
m++;
}
System.out.println(pathafter);
// pathafter= "/test ";
ftpclient.sendServer( "XMKD " + pathafter + "\r\n ");
}
catch (Exception e) {e.printStackTrace();}
}
else{*/
try{
String path=filelist[i].getParent();
String[] pathsplit=path.split( "\\\\ ");
int j=pathsplit.length-1;
int m=1;
String pathafter= "/ ";
while(m <=j)
{
if(m <j)pathafter=pathafter.concat(pathsplit[m])+ "/ ";
else pathafter=pathafter.concat(pathsplit[m]);
m++;
}
ftpclient.cd(pathafter);
String name=filelist[i].getName();
//File f=new File(path,name);
ftpclient.binary();
FileInputStream input=new FileInputStream(filelist[i]);
TelnetOutputStream output=ftpclient.put(name);
int bytesRead;
while((bytesRead=input.read())!=-1)
output.write(bytesRead);
input.close();
output.close();
}
catch (Exception e) {e.printStackTrace();}
//}
i--;
}
//**********************************************
}
catch(Exception ee){}
Logout();
}
}
public class FTPtxt {
public static void main(String args[])
{
FtpConnection ftp=new FtpConnection();
ftp.start();
}
}
[解决办法]
本段程序是实现按照本地机器上的一个文件夹目录结构传送到FTP服务器上的功能,为了简化方便高手的解答我只传送一层,多层跟这个一样的问题!下面程序中一个是判断文件和文件夹的,两个相互分开时,可以运行,但放在一起会出错!
错误信息:
java.io.FileNotFoundException: CWD /2: 550 /2/???¨??????: Failed to create.
1.用递归解决,多曾问题
2.java.io.FileNotFoundException: CWD /2: 550 /2/???¨??????: Failed to create
操作系统因该是LINUX,550是没有权限操作这个文件,TELNET过去加权限
[解决办法]
不懂 帮顶
[解决办法]
java.io.FileNotFoundException: CWD /2: 550 /2/???¨??????: Failed to create
lz,看看文件夹2下面的文件名了吗?是一堆问号,文件名是不是中文?如果是的话,建议你把InputStream和OutputStream转换为BufferedReader和BufferedWriter试试。
FileInputStream input=new FileInputStream(filelist[i]);
BufferedReader br = new BufferedReader(new InputStreamReader(input));
BufferedWriter类似。
[解决办法]
(1)可能编码问题,导致识别文件夹错误,于是无法创建文件,你全部改成英文试试
(2)创建文件所在的文件夹不存在,可以先手工把路径就建立起来,然后再试试
[解决办法]
来领分呵呵
===
在ftpclient.sendServer( "XMKD " + pathafter + "\r\n ");之后加上这句:
ftpclient.readServerResponse();
[解决办法]
你的linux系统下的/root路径下没有/2文件夹,手动建一个再试试。