pom依賴引入
commons-net
commons-net
3.3
實現**
@service
public class ftpserviceimpl ")
private string ftphost; //ftp伺服器位址
@value("$")
private int ftpport; //ftp伺服器端口
@value("$")
private string ftpusername; //ftp伺服器使用者名稱
@value("$")
private string ftppassword; //ftp伺服器使用者密碼
public ftpclient ftpclient = null;
/*** 連線ftp伺服器
* @return
* @throws socketexception
* @throws ioexception
*/public ftpclient getftpclient() throws socketexception, ioexception
} catch (socketexception e) catch (ioexception e)
return ftpclient;
}/**
* 上傳檔案
** @param pathname ftp服務儲存位址
* @param filename 上傳到ftp的檔名
* @param originfilename 待上傳檔案的名稱(絕對位址) *
* @return
*/public boolean uploadfile(string pathname, string filename, string originfilename) throws exception
/*** 上傳檔案流
** @param realpathname ftp服務儲存位址
* @param uuidname 上傳到ftp的檔名
* @param inputstream 輸入檔案流
* @return
*/public boolean uploadfile(string realpathname, string uuidname, inputstream inputstream) throws exception catch (exception e) finally catch (ioexception e) }}
return flag;
}/**
* 寫入字串文字
* @param realpathname ftp服務儲存位址
* @param filename ftp檔名
* @param content 上傳文字內容
* @throws exception
*/public void writeinto(string realpathname,string filename,string content) throws exception catch (exception e) finally catch (ioexception e) }}
}//改變目錄路徑
public boolean changeworkingdirectory(string directory) throws exception else
} catch (ioexception ioe)
return flag;
}//建立多層目錄檔案,如果有ftp伺服器已存在該檔案,則不建立,如果無,則建立
public boolean createdirecroty(string remote) throws exception else
end = directory.indexof("/", start);
string path = "";
string paths = "";
while (true) else
} else
paths = paths + "/" + subdirectory;
start = end + 1;
end = directory.indexof("/", start);
// 檢查所有目錄是否建立完畢
if (end <= start) }}
return success;
}//判斷ftp伺服器檔案是否存在
public boolean existfile(string path) throws ioexception
return flag;
}//建立目錄
public boolean makedirectory(string dir) else
} catch (exception e)
return flag;
}/**
** @param pathname ftp伺服器檔案目錄 *
* @param filename 檔名稱 *
* @return
*/public boolean downloadfile(string pathname, string filename) throws exception
}ftpclient.logout();
flag = true;
} catch (exception e) finally catch (ioexception e)
}if (null != os) catch (ioexception e) }}
return flag;
}/**
* 刪除檔案 *
** @param pathname ftp伺服器儲存目錄 *
* @param filename 要刪除的檔名稱 *
* @return
*/public boolean deletefile(string pathname, string filename) throws exception catch (exception e) finally catch (ioexception e) }}
return flag;
}}
FTP檔案上傳
是網上找的例子,原文找不到了。public class ftputils2 return 判斷是否登入成功 public boolean ftplogin else ftp伺服器連線回答 int reply this.ftpclient.getreplycode if ftpreply.isposi...
FTP上傳檔案
工作中要發布 或者api,之前採用過vs自帶的ftp發布方式,但感覺不太自由,不能部分更新發布 後來就採用vs檔案發布,然後手動的將發布的檔案放到伺服器上,每次發布都要開啟伺服器不太方便。就採用了現在的方式 服務端filezilla 客戶端flashfxp。這裡記錄一下安裝和除錯filezilla ...
FTP上傳檔案demo
直接上 了,jar包自己找吧。description 向ftp伺服器上傳檔案 param url ftp伺服器hostname param port ftp伺服器端口 param username ftp登入賬號 param password ftp登入密碼 param path ftp伺服器儲存目...