//////1.从ftp
服务器的指定目录下获得
文件列表//////ftp服务器IP(DNS)地址///对ftp服务器上的目录或文档的 *** 作方式///publicstaticvoidGetFileList(stringpath,stringWRMethods){string[]downloadFilesWebResponseresponse=nullStreamReaderreader=nullStringBuilderresult=newStringBuilder()try{//连接ftp服务器ConnectFtpServer(path)//设定要传送到ftp服务器的命令reqFTP.Method=WRMethods//传回ftp服务器回应response=reqFTP.GetResponse()reader=newStreamReader(response.GetResponseStream(),Encoding.Default)stringline=reader.ReadLine()while(line!=null){if(line.Substring(line.LastIndexOf('.')+1,3)=="xml"){result.Append(line)result.Append("\n")}line=reader.ReadLine()}if(string.IsNullOrEmpty(result.ToString())==true||result.ToString().Length0){DownLoad(localFolder,downloadFiles)}reader.Close()response.Close()_job_Message+="本次读取到的文件列表为:"+result///删除FTP上的文件DeleteFileName(localFolder,downloadFiles)}}catch(Exceptionex){_job_Err_Message+="3.从FTP远端主机的
根目录下获得文件列表时发生的错误讯息:"+ex.Message.ToString()+""downloadFiles=null}}package test
import java.io.DataInputStream
import sun.net.ftp.FtpClient
public class FtpDown1 {
public static void main(String args[]) throws Exception {
String host = "ip地址"
String path = ""
String username = "用户名"
String password = "密码"
FtpClient client = new FtpClient(host)
client.login(username, password)
client.binary()
client.cd("/目录名称")//如果是根目录下直接写个/就行了,或者不写
DataInputStream dis =new DataInputStream(client.nameList("test_*.xml"))
int readCount
String s=""
while((s=dis.readLine())!=null) {
//在此处判断是否存在对应的文件
System.out.println("Getting: " + s)
}
}
}
评论列表(0条)