跟着我做就是了,这个可是我现场测试和编写的哦!!没有任何copy
(1)把mysql的驱动放到tomcat的lib中 驱动是这个
>
java测试连接ftp是否连通可以使用判断是否有异常来决定,实例如下:
/connectServer
连接ftp服务器
@throws javaioIOException
@param path 文件夹,空代表根目录
@param password 密码
@param user 登陆用户
@param server 服务器地址
/
public void connectServer(String server, String user, String password, String path)
throws IOException
{
// server:FTP服务器的IP地址;user:登录FTP服务器的用户名
// password:登录FTP服务器的用户名的口令;path:FTP服务器上的路径
ftpClient = new FtpClient();
ftpClientopenServer(server);
ftpClientlogin(user, password);
//path是ftp服务下主目录的子目录
if (pathlength() != 0) ftpClientcd(path);
//用2进制上传、下载
ftpClientbinary();
}
/
upload
上传文件
@throws javalangException
@return -1 文件不存在
-2 文件内容为空
>0 成功上传,返回文件的大小
@param newname 上传后的新文件名
@param filename 上传的文件
/
public long upload(String filename,String newname) throws Exception
{
long result = 0;
TelnetOutputStream os = null;
FileInputStream is = null;
try {
javaioFile file_in = new javaioFile(filename);
if (!file_inexists()) return -1;
if (file_inlength()==0) return -2;
os = ftpClientput(newname);
result = file_inlength();
is = new FileInputStream(file_in);
byte[] bytes = new byte[1024];
int c;
while ((c = isread(bytes)) != -1) {
oswrite(bytes, 0, c);
}
} finally {
if (is != null) {
isclose();
}
if (os != null) {
osclose();
}
}
return result;
}
/
upload
@throws javalangException
@return
@param filename
/
public long upload(String filename)
throws Exception
{
String newname = "";
if (filenameindexOf("/")>-1)
{
newname = filenamesubstring(filenamelastIndexOf("/")+1);
}else
{
newname = filename;
}
return upload(filename,newname);
}
/
download
从ftp下载文件到本地
@throws javalangException
@return
@param newfilename 本地生成的文件名
@param filename 服务器上的文件名
/
public long download(String filename,String newfilename)
throws Exception
{
long result = 0;
TelnetInputStream is = null;
FileOutputStream os = null;
try
{
is = ftpClientget(filename);
javaioFile outfile = new javaioFile(newfilename);
os = new FileOutputStream(outfile);
byte[] bytes = new byte[1024];
int c;
while ((c = isread(bytes)) != -1) {
oswrite(bytes, 0, c);
result = result + c;
}
} catch (IOException e)
{
eprintStackTrace();
}
finally {
if (is != null) {
isclose();
}
if (os != null) {
osclose();
}
}
return result;
}
/
取得某个目录下的所有文件列表
/
public List getFileList(String path)
{
List list = new ArrayList();
try
{
DataInputStream dis = new DataInputStream(ftpClientnameList(path));
String filename = "";
while((filename=disreadLine())!=null)
{
listadd(filename);
}
} catch (Exception e)
{
eprintStackTrace();
}
return list;
}
/
closeServer
断开与ftp服务器的链接
@throws javaioIOException
/
public void closeServer()
throws IOException
{
try
{
if (ftpClient != null)
{
ftpClientcloseServer();
}
} catch (IOException e) {
eprintStackTrace();
}
}
public static void main(String [] args) throws Exception
{
FtpUtil ftp = new FtpUtil();
try {
//连接ftp服务器
ftpconnectServer("10163715", "cxl", "1", "info2");
/ 上传文件到 info2 文件夹下 /
Systemoutprintln("filesize:"+ftpupload("f:/download/Installexe")+"字节");
/ 取得info2文件夹下的所有文件列表,并下载到 E盘下 /
List list = ftpgetFileList("");
for (int i=0;i<listsize();i++)
{
String filename = (String)listget(i);
Systemoutprintln(filename);
ftpdownload(filename,"E:/"+filename);
}
} catch (Exception e) {
///
}finally
{
ftpcloseServer();
}
}
}
这个命令显示在/ptc 目录下扩展名为jsp 且内容包含version 字符串的文件,显示文件目录 和包含这个字符串的行。 find /ptc -exec grep -l "sjh" {} \; 在/ptc 下查找内容包含“sjh"字符串的文件。显示文件目录。 find /tmpftp xargs egrep version find 里面的-exec 效率没 xargs 逐条递送处理的效果好 grep 查找也没 egrep 效率快。 不过只能对非特殊字符。
不行的,除非FTP软件 或者架设有BUG。
如果你是架设网站,文件上传成功需要打开网站首页运行初始化程序。
比如INDEX 或者HTML ASP JSP等等 具体请看网站架设说明。
因为FTP服务器 权限只有读写文件权限,没有执行权限。
以上就是关于网站开发、维护,网页制作,专业的来!全部的内容,包括:网站开发、维护,网页制作,专业的来!、ftp工具是什么、如何在jsp页面提取出客户端的mac地址等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)