練功房推薦書單

  • 猛虎出柙雙劍合璧版--最新 OCA / OCP Java SE 7 Programmer 專業認證 (電子書)
  • 流浪教師存零股存到3000萬(全新增修版)(書+DVD)
  • 開始在關西自助旅行(京都‧大阪‧神戶‧奈良)(全新增訂版)
  • 不敗教主的300張股票存股術

JSP精選實用範例(四):檔案傳輸 RSS feed
討論區首頁 » 網頁程式設計 Web Development
發表人 內容
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
預先安裝函式庫:Apache Commons Net
程式碼:
ftptest.jsp:

<%@ page import="java.io.File"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.io.IOException"%>
<%@ page import="org.apache.commons.net.ftp.FTP"%>
<%@ page import="org.apache.commons.net.ftp.FTPClient"%>
<%@ page import="org.apache.commons.net.ftp.FTPFile"%>
<%@ page import="org.apache.commons.net.ftp.FTPReply"%>
<%
String server = "192.168.1.2";
String username = "andowson";
String password = "changeit";
String directory = "download";
String filename = "C:\\Users\\Andowson\\Desktop\\jspSmartUpload.zip";
File filePut = new File(filename);
String filename2 = "C:\\Users\\Andowson\\Desktop\\commons-net-1.4.1.zip";
File fileGet = new File(filename2);
String filename3 = "jdk-6u3-windows-i586-p.exe";

FTPClient ftp = new FTPClient();
// We want to timeout if a response takes longer than 30 seconds
ftp.setDefaultTimeout(30000);
try {
int reply;
ftp.connect(server);
System.out.println("Connected to " + server + ".");
System.out.print(ftp.getReplyString());

// After connection attempt, you should check the reply code to verify
// success.
reply = ftp.getReplyCode();

if (!FTPReply.isPositiveCompletion(reply)) {
ftp.disconnect();
System.err.println("FTP server refused connection.");
return;
}
// transfer files
if (ftp.login(username, password)) {
long totalSize = 0L;
for (FTPFile file : ftp.listFiles(directory)) {
System.out.printf("%s %s [%d bytes]\n",
(file.isDirectory() ? "[D]" : " "), file.getName(), file.getSize());
if (!file.isDirectory()) {
totalSize += file.getSize();
}
}
System.out.println("totalSize = " + totalSize/(1024 * 1024) + "MB");

// PASV
ftp.enterLocalPassiveMode();
// CWD
ftp.changeWorkingDirectory(directory);
// PWD
System.out.println(ftp.printWorkingDirectory());
// TYPE I
ftp.setFileType(FTP.BINARY_FILE_TYPE);
// PUT
ftp.storeFile(filePut.getName(), new FileInputStream(filePut));
// GET
ftp.retrieveFile(fileGet.getName(), new FileOutputStream(fileGet));
// DELE
ftp.deleteFile(filename3);
}
ftp.logout();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp.isConnected()) {
try {
ftp.disconnect();
} catch (IOException ioe) {
// do nothing
}
}
}
%>

參考資料:
http://commons.apache.org/net/apidocs/index.html
 檔案名稱 ftptest.jsp [Disk] 下載
 描述 FTP Client 範例程式
 檔案大小 2 Kbytes
 下載次數:  88 次


分享經驗 累積智慧
[WWW]
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
預先安裝函式庫:edtFTPj/Free
程式碼:
ftpdemo.jsp:

<%@ page import="java.io.File"%>
<%@ page import="java.util.Locale"%>
<%@ page import="com.enterprisedt.net.ftp.FTPClient"%>
<%@ page import="com.enterprisedt.net.ftp.FTPConnectMode"%>
<%@ page import="com.enterprisedt.net.ftp.FTPException"%>
<%@ page import="com.enterprisedt.net.ftp.FTPFile"%>
<%@ page import="com.enterprisedt.net.ftp.FTPMessageCollector"%>
<%@ page import="com.enterprisedt.net.ftp.FTPReply"%>
<%@ page import="com.enterprisedt.net.ftp.FTPTransferType"%>
<%@ page import="com.enterprisedt.net.ftp.UnixFileParser"%>
<%
// assign args to make it clear
String server = "192.168.1.2";
String username = "andowson";
String password = "changeit";
String directory = "download";
String filename = "C:\\Users\\Andowson\\Desktop\\jspSmartUpload.zip";
File filePut = new File(filename);
String filename2 = "C:\\Users\\Andowson\\Desktop\\commons-net-1.4.1.zip";
File fileGet = new File(filename2);
String filename3 = "jdk-6u3-windows-i586-p.exe";

FTPClient ftp = new FTPClient();
// We want to timeout if a response takes longer than 30 seconds
ftp.setTimeout(30000);

try {
// set up client
ftp.setRemoteHost(server);
FTPMessageCollector listener = new FTPMessageCollector();
ftp.setMessageListener(listener);

// connect
ftp.connect();
System.out.println("Connected to " + server + ".");
String messages = listener.getLog();
System.out.print(messages);

FTPReply reply = ftp.getLastReply();
if (reply != null) {
System.out.print(reply.getRawReply());
//String replyCode = reply.getReplyCode();
System.out.print(reply.getReplyCode());
}

// login
ftp.login(username, password);

// set up passive BINARY transfers
ftp.setConnectMode(FTPConnectMode.PASV);
// get directory and print it to console
UnixFileParser ufp = new UnixFileParser();
ufp.setLocale(new Locale("en", "US"));
String[] files = ftp.dir(directory, true);
long totalSize = 0L;
for (int i = 0; i < files.length; i++) {
//System.out.println(files[i]);
FTPFile file = ufp.parse(files[i]);
System.out.printf("%s %s [%d bytes]\n",
(file.isDir() ? "[D]" : " "), file.getName(), file.size());
if (!file.isDir()) {
totalSize += file.size();
}
}
System.out.println("totalSize = " + totalSize / (1024 * 1024) + "MB");
ftp.chdir(directory);
System.out.println(ftp.pwd());
ftp.setType(FTPTransferType.BINARY);

// copy file to server
ftp.put(filename, filePut.getName());

// copy file from server
ftp.get(filename2, fileGet.getName());

// delete file from server
ftp.delete(filename3);

// Shut down client
ftp.quit();
} catch (FTPException e) {
e.printStackTrace();
} finally {
if (ftp.connected()) {
try {
ftp.quit();
} catch (Exception e) {
// do nothing
}
}
}
%>


備註:
edtFTPj的函式名稱跟FTP指令的名稱相當接近,使用起來比較直覺,但39-44行部分印不出東西來,不知道為什麼抓不到replyCode,如果您有試出來,請告知一下。
 檔案名稱 ftpdemo.jsp [Disk] 下載
 描述 FTP Demo Using Enterprise Distributed Technologies FTP for Java component
 檔案大小 3 Kbytes
 下載次數:  30 次


分享經驗 累積智慧
[WWW]
viva

八級學員
[Avatar]

註冊時間: 2008/8/21
文章: 24
來自: 台北
離線
不好意思請問一下
ftptest.jsp裡有這一行 ftp.setDefaultTimeout(30000);
設定這時間是什麼意思?
[Email]
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
viva wrote:不好意思請問一下
ftptest.jsp裡有這一行 ftp.setDefaultTimeout(30000);
設定這時間是什麼意思?

原來的程式碼上寫了:
// We want to timeout if a response takes longer than 30 seconds
ftp.setDefaultTimeout(30000);
因為setDefaultTimeout(int timeout)裡面timeout的單位是milliseconds(千分之一秒),故我們要乘上1000,就變成30000。
至於為何要設定Timeout,是因為在建立TCP的socket連線時,需要等候連線的對方回應ACK,以確認對方還活著,而這個等候的時間就是Timeout的時間,超過這個時間,我們就認為對方掛了,這個connection就無法成功建立。

分享經驗 累積智慧
[WWW]
viva

八級學員
[Avatar]

註冊時間: 2008/8/21
文章: 24
來自: 台北
離線
不好意思,在請教一下
ftp.setDefaultPort(21);
這語法的用意是什麼?為何會設21與13?
若不加這行,也OK嗎?
[Email]
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
viva wrote:不好意思,在請教一下
ftp.setDefaultPort(21);
這語法的用意是什麼?為何會設21與13?
若不加這行,也OK嗎?

因為FTP通訊協定預設的通訊埠是21,而org.apache.commons.net.ftp.FTP.DEFAULT_PORT的值即為21,所以如果您要連的FTP Server沒有改過port號的話,不用加這一行也OK。
另外,我的範例程式中應該是沒加這一行,也沒看到什麼13的數字,所以我無法回答「為何會設21與13?」

分享經驗 累積智慧
[WWW]
viva

八級學員
[Avatar]

註冊時間: 2008/8/21
文章: 24
來自: 台北
離線
之前在Google找了一些FTP連線的資料
因看到有些範例會加那行...所以才不懂為何是21與13
不過現在了解了,感謝你的指導!!

在請教一下...(我好像問題好多,不知道會不會造成你困擾)
我已經寫好我自己要使用的FTP程式...
但....如果在FTP設定伺服器種類設為FTPES-透過外顯式TLS/SSL的FTP
那我的FTP程式還連的上嗎?
[Email]
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
viva wrote:
在請教一下...(我好像問題好多,不知道會不會造成你困擾)
我已經寫好我自己要使用的FTP程式...
但....如果在FTP設定伺服器種類設為FTPES-透過外顯式TLS/SSL的FTP
那我的FTP程式還連的上嗎?


有問題互相討論是OK的,不過希望能提供較多的資訊,例如完整或部分的程式碼,這樣子別人對於您的問題的內容會比較清楚。
目前支援FTPS的Java FTP Library大多是commercial component,如edtFTPj/Pro。所以您的程式需要換掉Library及修改部分程式碼才能連上。
我找到了一個FTPES的範例程式,網址如下:
http://www.example-code.com/java/ftp_AuthSSL.asp
您可以參考,用到的元件下載網址如下:
http://www.chilkatsoft.com/download/ChilkatJava.zip

分享經驗 累積智慧
[WWW]
viva

八級學員
[Avatar]

註冊時間: 2008/8/21
文章: 24
來自: 台北
離線
程式碼裡呼叫了一些function,是自訂的!
原本用意是想上傳某個檔案到A SERVER,再從A SERVER上傳到B SERVER
而以下程式就是做從A SERVER上傳到B SERVER
檔案下載沒用到,所以他把"罵克"起來

感謝andowson的指導,這支FTP程式學到了很多,謝謝!

<%@ page contentType="text/html; charset=BIG5" %>

<jsp:useBean id="dbOprBean" scope="page" class="com.gemmyplanet.dbbean.DBOperationBean" />
<jsp:setProperty name="dbOprBean" property="*" />
<%@ include file="inc_common_parameters.jsp" %>
<%@ include file="inc_common_fun_ecindp.jsp" %>
<%@ include file="inc_common_fun_doc.jsp" %>
<%@ include file="inc_gp_fun_mysql5.jsp" %>
<%@ page import="java.io.*"%>
<%@ page import="java.util.*"%>
<%@ page import="org.apache.commons.net.ftp.*"%>
<%
/////////////////////////////////////////////////
// 接收參數
//////////////////////////////////////////////////
String GPBID = null;
try{
GPBID = request.getParameter("GPBID");
if( GPBID == null )
gERR = 1;
}catch(Exception e) {
gERR = 1;
gERRMSG = "lack parameter";
}

/////////////////////////////////////////////////
// 宣告參數
//////////////////////////////////////////////////
String server = "主機名稱";
String login = "帳號";
String password = "密碼";
String Ftp_Upload_FileName = ""; //上傳檔名
GPDatabaseTK gpdb = new GPDatabaseTK(dbOprBean, "BIG5");
GPJAVATK gpjtk = new GPJAVATK(gpdb);

/////////////////////////////////////////////////
// 取出檔名並重新命名
//////////////////////////////////////////////////
if( gERR == 0 ) {
BANNERINFO bannerinfo = gpjtk.getBannerFilename( GPBID ); //以 GPBID 抓 Banner 檔名
if( bannerinfo != null ) {
String[] tokens = (bannerinfo.mFILENAME).split("\\/");
Ftp_Upload_FileName = tokens[(tokens.length)-1];

/////////////////////////////////////////////////
// 連接 FTP
//////////////////////////////////////////////////
FTPClient ftp = new FTPClient(); //連接、登錄服務器
ftp.setDefaultTimeout(30000); //等候連線的對方回應ACK的時間

try {
int reply;
String UploadCatalog = "/public_html/res"; //上傳到哪個目錄下/public_html/res
ftp.setDefaultPort(21);
ftp.connect( server ); //連接FTP
ftp.login( login, password ); //登入
ftp.changeWorkingDirectory( UploadCatalog ); //當下在 Ftp 服務器上的工作目錄
reply = ftp.getReplyCode();

if ( !FTPReply.isPositiveCompletion(reply) ) { //判斷是否連線成功?
ftp.logout(); //退出 FTP 服務器
ftp.disconnect(); //關閉連接
%> <script language=javascript>
window.alert("FTP連線失敗!");
location.href="http://失敗後返回的網址";
</script>
<%
} else {
/*
FTPFile[] list = ftp.listFiles(); //獲得當前 FTP 服務器工作目錄中的文件列表
for (int i = 0; i < list.length; i++) {
String name = list[i].getName(); //取得檔名
out.println("FTP檔名 : " + name+"<br>");
}
*/
/////////////////////////////////////////////////
// 檔案上傳
//////////////////////////////////////////////////
try {
int file_size;
//圖檔路徑 "C:/Program Files/Apache Group/Tomcat 4.1/webapps/gp_image/res/"+Ftp_Upload_FileName
String path = gWEBROOT+"/gp_image/res/"+Ftp_Upload_FileName;
File file = new File(path);
if( file.exists() ) {
FileInputStream fis = new FileInputStream(file);
ftp.setBufferSize(1024);
ftp.setFileType(ftp.BINARY_FILE_TYPE); //設置文件類型(二進制),圖檔都用BINARY_FILE_TYPE
ftp.storeFile( Ftp_Upload_FileName , fis );
fis.close(); //關閉串流

/////////////////////////////////////////////////
// 檔案下載
//////////////////////////////////////////////////
/*
String remoteFileName = "/ftp_test/01.jpg";
File file = new File("c:/999999999.jpg");
FileOutputStream fos = new FileOutputStream(file);
ftp.setBufferSize(1024);
ftp.setFileType(ftp.BINARY_FILE_TYPE); //設置文件類型(二進制),圖檔都用BINARY_FILE_TYPE
ftp.retrieveFile(remoteFileName, fos);
fos.close();
if( file.exists() ) {
out.println("檔案存在<br>");
} else {
out.println("檔案不存在");
}
*/
if (ftp != null && ftp.isConnected()) {
ftp.logout(); //退出 FTP 服務器
ftp.disconnect(); //關閉連接
}
%> <script language=javascript>
window.alert("上傳成功!");
location.href="http://成功後返回的網址";
</script>
<% } else {
if (ftp != null && ftp.isConnected()) {
ftp.logout(); //退出 FTP 服務器
ftp.disconnect(); //關閉連接
}
%> <script language=javascript>
window.alert("檔案不存在!");
location.href="http://返回網址";
</script>
<% }
} catch (IOException e) {
%> <script language=javascript>window.alert("FTP上傳失敗!<%=e.getMessage()%>!");</script>
<% //e.printStackTrace();
//throw new RuntimeException("FTP客戶端錯誤!", e);
}
}
} catch (Exception e) {
%> <script language=javascript>window.alert("FTP上傳失敗!<%=e.getMessage()%>!請重試!");</script>
<% }
}
}
%>
[Email]
viva

八級學員
[Avatar]

註冊時間: 2008/8/21
文章: 24
來自: 台北
離線
andowson 請教一下...
如果要上傳檔案之前,我想在FTP上判斷A目錄是否存在?
如果存在,就放入A目錄
不存在,就建立( makeDirectory() )A目錄....

判斷A目錄是否存在該怎麼做?
[Email]
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
這個很簡單啊,用FTPClient類別的listFiles()來取得現行工作目錄的檔案清單(FTPFile[]),然後跑一個for迴圈,將每個元素拿出來判斷是否是一個目錄(isDirectory())且名稱(getName())等於目錄A,如果存在就終止迴圈,並將變數dirExist設定為true。

if (ftp.login(username, password)) {
boolean dirExist = false;
String dirA = "upload";
FTPFile[] files = ftp.listFiles();
for (int i = 0; i < files.length; i++) {
if (files[i].isDirectory() && files[i].getName().equals(dirA)) {
dirExist = true;
break;
}
}
out.println("directory " + dirA + " exists? " + dirExist);
if (!dirExist) {
ftp.makeDirectory(dirA);
}
}

分享經驗 累積智慧
[WWW]
viva

八級學員
[Avatar]

註冊時間: 2008/8/21
文章: 24
來自: 台北
離線
感謝指導....^^
[Email]
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
FTPS(FTP Secure or FTP over SSL/TLS)

預先安裝函式庫:ftp4che, log4j
程式碼:
ftp4che.jsp:

<%@ page import="java.io.File"%>
<%@ page import="java.io.IOException"%>
<%@ page import="org.ftp4che.*"%>
<%@ page import="org.ftp4che.util.ftpfile.*"%>
<%@ page import="org.ftp4che.exception.*"%>
<%@ page import="org.ftp4che.impl.SecureFTPConnection"%>
<%
String server = "192.168.1.2";
String username = "andowson";
String password = "changeit";
String directory = "download";
String filename = "C:\\Users\\Andowson\\Desktop\\jspSmartUpload.zip";
File filePut = new File(filename);
String filename2 = "C:\\Users\\Andowson\\Desktop\\commons-net-1.4.1.zip";
File fileGet = new File(filename2);
String filename3 = "jdk-6u3-windows-i586-p.exe";

FTPConnection ftp = null;
try {
ftp = FTPConnectionFactory.getInstance(server, 21, username, password, FTPConnection.AUTH_TLS_FTP_CONNECTION, true);
ftp.connect();
System.out.println("Connected to " + server + ".");

// transfer files
long totalSize = 0L;
for (FTPFile file : ftp.getDirectoryListing(directory)) {
System.out.printf("%s %s [%d bytes]\n",
(file.isDirectory() ? "[D]" : " "), file.getName(), file.getSize());
if (!file.isDirectory()) {
totalSize += file.getSize();
}
}
System.out.println("totalSize = " + totalSize/(1024 * 1024) + "MB");

// PASV
ftp.setPassiveMode(true);
// CWD
ftp.changeDirectory(directory);
// PWD
System.out.println(ftp.getWorkDirectory());
// PUT
FTPFile fromFile = new FTPFile(filePut);
FTPFile toFile = new FTPFile(new File(filePut.getName()));
ftp.uploadFile(fromFile, toFile);
// GET
fromFile = new FTPFile(new File(fileGet.getName()));
toFile = new FTPFile(fileGet);
ftp.downloadFile(fromFile, toFile);
// DELE
ftp.deleteFile(new FTPFile(new File(filename3)));
} catch (NotConnectedException nce) {
nce.printStackTrace();
} catch (FtpFileNotFoundException ffnfe) {
ffnfe.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (ftp != null) {
ftp.disconnect();
}
}
%>

備註:
最近找到了支援FTPS的免費Java FTP Library(採用LGPL授權) -- ftp4che,將原先的程式碼略微修改一下,搭配FileZilla Server測試一下,可以成功執行。
參考資料:
http://www.javaworld.com.tw/jute/post/view?bid=11&id=237813&sty=3
 檔案名稱 ftp4che.jsp [Disk] 下載
 描述 FTPS檔案傳輸程式
 檔案大小 2 Kbytes
 下載次數:  19 次


分享經驗 累積智慧
[WWW]
andowson

七段學員
[Avatar]

註冊時間: 2007/1/2
文章: 711
來自: 台北
離線
SFTP(SSH File Transfer Protocol or FTP over SSH)

預先安裝函式庫:JSch(Java Secure Channel)
程式碼:
sftp.jsp:

<%@ page import="java.io.File"%>
<%@ page import="java.io.FileInputStream"%>
<%@ page import="java.io.FileOutputStream"%>
<%@ page import="java.util.Properties"%>
<%@ page import="java.util.Vector"%>
<%@ page import="com.jcraft.jsch.Channel"%>
<%@ page import="com.jcraft.jsch.ChannelSftp"%>
<%@ page import="com.jcraft.jsch.JSch"%>
<%@ page import="com.jcraft.jsch.Session"%>
<%@ page import="com.jcraft.jsch.ChannelSftp.LsEntry"%>
<%
try {
String host = "192.168.1.2";
int port = 22;
String username = "andowson";
String password = "changeit";
String directory = "/home/andowson/download/";
String uploadFile = "C:\\temp\\upload.txt";

String downloadFile = "C:\\temp\\download.txt";
String deleteFile = "delete.txt";

//
// First Create a JSch session
//
System.out.println("Creating session.");
JSch jsch = new JSch();
ChannelSftp sftp = null;

//
// Now connect and SFTP to the SFTP Server
//
try {
// Create a session sending through our username and password
Session sshSession = jsch.getSession(username, host, port);
System.out.println("Session created.");
sshSession.setPassword(password);
// Security.addProvider(new com.sun.crypto.provider.SunJCE());

//
// Setup Strict HostKeyChecking to no so we don't get the
// unknown host key exception
//
Properties sshConfig = new Properties();
sshConfig.put("StrictHostKeyChecking", "no");
sshSession.setConfig(sshConfig);
sshSession.connect();
System.out.println("Session connected.");

//
// Open the SFTP channel
//
System.out.println("Opening Channel.");
Channel channel = sshSession.openChannel("sftp");
channel.connect();
sftp = (ChannelSftp) channel;
System.out.println("Connected to " + host + ".");
} catch (Exception e) {
System.err.println("Unable to connect to FTP server." + e.toString());
throw e;
}

//
// Change to the remote directory
//
System.out.println("Changing to FTP remote dir: " + directory);
// CWD
sftp.cd(directory);
// PWD
System.out.println(sftp.pwd());

//
// Send the file we generated, PUT
//
File filePut = new File(uploadFile);
try {
System.out.println("Storing file as remote filename: " + filePut.getName());
sftp.put(new FileInputStream(filePut), filePut.getName());
} catch (Exception e) {
System.err.println("Storing remote file failed." + e.toString());
throw e;
}

//
// Get the list of files in the remote server directory
//
Vector files = sftp.ls(directory);

//
// Log if we have nothing to download
//
if (files.size() == 0) {
System.out.println("No files are available for download.");
}
//
// Otherwise download all files except for the . and .. entries
//
else {
long totalSize = 0L;
for (int i = 0; i < files.size(); i++) {
LsEntry file = (LsEntry) files.get(i);
if (!file.getFilename().equals(".") && !file.getFilename().equals("..")) {
System.out.printf("%s %s [%d bytes]\n",
(file.getAttrs().isDir() ? "[D]" : " "), file.getFilename(), file.getAttrs().getSize());
if (!file.getAttrs().isDir()) {
totalSize += file.getAttrs().getSize();
}
}
}
System.out.println("totalSize = " + totalSize/(1024 * 1024) + "MB");
//
// Get the file and write it to our local file system, GET
//
System.out.println("Downloading file " + filePut.getName());
File fileGet = new File(downloadFile);
sftp.get(filePut.getName(), new FileOutputStream(fileGet));
//
// Remove the file from the server, DELE
//
System.out.println("Deleting file " + deleteFile);
sftp.rm(deleteFile);
}

//
// Disconnect from the FTP server
//
try {
sftp.quit();
} catch (Exception e) {
System.err.println("Unable to disconnect from FTP server. " + e.toString());
}

} catch (Exception e) {
System.err.println("Error: " + e.toString());
e.printStackTrace();
}

System.out.println("Process Complete.");
%>

參考資料:
Sending Files via FTP From Your Java Applications - Part 2 of 2 - Using Jsch for SFTP
 檔案名稱 sftp.jsp [Disk] 下載
 描述 Java SFTP範例程式
 檔案大小 4 Kbytes
 下載次數:  41 次


分享經驗 累積智慧
[WWW]
johnny0917

十級學員

註冊時間: 2014/11/6
文章: 1
離線
不好意思請問一下對程式沒研究很深,有個問題想問一下
我看到有篇文章主題: JSP精選實用範例(四):檔案傳輸 中的檔案是ftptest.jsp

問題一:jsp 以下一行的ftp 的 passive mode連線方式這方法只有jsp能執行,那一般windows bat檔有辦法可寫這塊或連接這塊的寫法嗎?
61 ftp.enterLocalPassiveMode();

問題二:我看jsp網頁有很多網有些的開頭函式庫這是jsp定義的嗎?
例如:
01 <%@ page import="java.io.File"%>
02 <%@ page import="java.io.FileInputStream"%>
03 <%@ page import="java.io.FileOutputStream"%>
04 <%@ page import="java.io.IOException"%>
05 <%@ page import="org.apache.commons.net.ftp.FTP"%>
06 <%@ page import="org.apache.commons.net.ftp.FTPClient"%>
07 <%@ page import="org.apache.commons.net.ftp.FTPFile"%>
08 <%@ page import="org.apache.commons.net.ftp.FTPReply"%>
 
討論區首頁 » 網頁程式設計 Web Development
前往:   
行動版