今回はデータの(暗黙の)「セーブ、ロード」処理(ファイル名は「FTPConnect.sr」としている)。
また複数のフォルダーの登録と、複数のフォルダーの単位の「アップロード、ダウンロード」(子フォルダーに対する再帰的な処理)。
TransferList にデータが存在する場合は「HostFolder、LocalFolder」のデータは無視され、TransferList にデータが存在しない場合は「HostFolder、LocalFolder」のデータで処理される。
《参考》
『Java2 FTP Connect 7』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+00000955.+&
『Java2 MouseDoubleClicked 1』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+0000096B.+&
『Java2 FTP Connect 8』
http://artemis.rosx.net/sjis/smt.cgi?r+izanami/&bid+00000918&tsn+0000096C-0000096D&
クラスパスの設定
http://www.hot-surprise.org/IntroEclipse/Operation/N01/3_3.html
FTP に関するプログラムは下記ページを参照.
JavaによるFTP転送サンプル | Pa-kun plus idea
http://web.plus-idea.net/2011/06/javaftp/
> client.setControlEncoding("MS932");
↑ Host 側のキャラクター・セットを設定すれば良いと思われる。
Windows 系では「CP932」(Microsoft Windows CodePage 932)、UNIX 系では「UTF-8、EUC-JP(日本の場合)」などが大半のようだ、Android は「UTF-8」となる。
厳密に言うと Windows のキャラクター・セットは「shift_jis」と完全な互換ではない、今まで Windows のキャラクター・セットのスタンダードな表記法は「CP932」だったが、「commons-net-3.3」では「MS932」でないとエラーになるようだ.
JavaでFTPアップロードを行う。 - sinsengumi.net
http://sinsengumi.net/blog/2011/02/java%E3%81%A7ftp%E3%82%A2%E3%83%83%E3%83%97%E3%83%AD%E3%83%BC%E3%83%89%E3%82%92%E8%A1%8C%E3%81%86%E3%80%82/
(分かりやすければ他のファイル名でも良い)「MainPanelDesign」(MainPanelDesign.java)ファイルを Visual Swing for Eclipse でビジュアルに画面デザイン(GUI 部品の配置)を作成している(Java コードが自動生成される)。
「MainAppFrameObj、MainPanelImplementationObj」 からアプレット独自メソッドにアクセスしているので、「MainAppFrameObj、MainPanelImplementationObj」はアプレット・クラス内に設置している。
(アプリーケーションの初期実行用) main( ) メソッドで(MainAppFrameObjなどのような)クラス内クラスをインスタンス化したい場合(main( ) メソッド実行時には、まだアプレット自体のインスタンスが生成されておらず、通常のクラス内クラスではインスタンス化できないので) 、クラス内クラスには「static」修飾子を付与しなければならない(この場合、オブジェクトは1つだけしか作成できない)。
クリック時にマウス・カーソルが動いてしまった場合 mouseClicked イベントだとイベントが発生しない"仕様"になっているようなので、mouse イベントに関しては mouseReleased イベントを使用している。
なお、ダブル・クリック検出用に mousePressed イベントも使用している。
変更した部分はイベント用メソッドの「ctfHostUserName、ctfHostName、cpfHostPassword、ctfHostFolder、ctfLocalFolder、ctfHostPortNum、ctaMessage、cltHostFileList、cltLocalFileList、ccbFTPFileDataType、ctpFileListTabs、cckHostPASVMode、ccbHostEncode、cpnFTPSetting、ctpBaseTabs、cltHostTransferList、cltLocalTransferList、ctpTransferListTabs」の private 修飾子を削除。
その他、「HostLogout_CbtMouseMouseReleased、HostLogin_CbtMouseMouseReleased、FTPFileList_CbtMouseMouseReleased、FTPDownload_CbtMouseMouseReleased、FTPUpload_CbtMouseMouseReleased、HostFileList_CbtNativeMouseMousePressed、HostFileList_CltNativeMouseMouseReleased、LocalFileList_CbtNativeMouseMousePressed、LocalFileList_CltNativeMouseMouseReleased、SetupFileList_HostFolder_CbtMouseMouseReleased、SetupFileList_LocalFolder_CbtMouseMouseReleased、FTPBreak_CbtMouseMouseReleased、TransferListEntry_CbtMouseMouseReleased、TransferListDelete_CbtMouseMouseReleased」変数の private 修飾子を削除(Button など Component を直にイジる必要がなければ private 修飾子を削除しなくても良い)。
『FTPConnect.java』
import java.awt.Dimension;
//Event を使う場合は、その Event に対応する「〜Adapter、〜Event」を import しなければならない。
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.SocketException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.swing.DefaultListModel;
import javax.swing.JApplet;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import org.apache.commons.net.ftp.FTP;
import org.apache.commons.net.ftp.FTPClient;
import org.apache.commons.net.ftp.FTPFile;
import org.apache.commons.net.ftp.FTPReply;
@SuppressWarnings("serial")
public class FTPConnect extends JApplet {
private static FTPConnect oMainApp;
private static boolean lApplication = false; // true; //
private static MainAppFrameObj oMainAppFrame;
private MainPanelImplementationObj oMainPanelImp;
private final String fvsSerialFile = "FTPConnect.sr";
private final String fvsSerialVersion = "1.1";
private final String fvsSnapShotFile = ".FTPConnect.SnapShot";
// private final String fvsPathListTag_Folder = ":+Folder:=";
private final String fvsPathListTag_File = "-<File>=";
private final String fvsReg_PathListTag_File = "\\-<File>=";
private final String fvsPathListTag_Folder = "+<Directory>=";
private final String fvsReg_PathListTag_Folder = "\\+<Directory>=";
private final String fvsPathListTag_TimeStamp = " <TimeStamp>=";
private final String fvsReg_PathListTag_TimeStamp = " <TimeStamp>=";
private Matcher matcher;
// Pattern pattern;
// Transfer // Connect
private boolean lFTPConnection = false; // true; //
private boolean lFTPBreak = false; // true; //
private FTPClient client;
// Binary転送Modeを利用?(true=Yes、false=No)
// TransferFileDataType
private static boolean lFTPTransfer_Binary = false; // true; //
// PASV Modeを利用?(true=Yes、false=No)
private static boolean lFTPPassiveMode = true; // false; //
private static final String fvsFTPTransfer_Binary = "Binary";
// 連想配列
private HashMap<String,String> da1CharEncodeSets;
private String vsHostEncode;
private String vsLocalEncode;
private String vsHostName;
private String vsHostPortNum;
private int iHostPortNum;
private String vsHostUserName;
private String vsHostPassword;
private String vsHostCurrent;
private String vsHostFolder;
private String vsLocalCurrent;
private String vsLocalFolder;
public static void main(String[] args) {
oMainApp = new FTPConnect( );
lApplication = true; // false;
oMainAppFrame =
new MainAppFrameObj( );
oMainAppFrame.oAppThread.start();
try{
oMainAppFrame.oAppThread.join();
}
catch(InterruptedException e){ }
// oMainAppFrame.oAppThread = null;
System.exit(0);
}
public void AppRepaint() {
System.out.println("AppRepaint( );");
repaint();
}
public void init() {
System.out.println("init( );");
oMainApp = this;
oMainPanelImp = new MainPanelImplementationObj();
Read( );
getContentPane().add(oMainPanelImp,"Center");
oMainPanelImp.setVisible(true);
if( oMainAppFrame!=null ){
System.out.println("if(lApplication)");
oMainAppFrame.setPreSize(oMainPanelImp.getSize( ));
System.out.println("MainPanelWidth="+oMainPanelImp.getSize( ).getWidth());
System.out.println("MainPanelHeight="+oMainPanelImp.getSize( ).getHeight());
}
System.out.println("Hello, World!");
// UTF8, Windows, EUC-JP, ASCII
da1CharEncodeSets = new HashMap<String, String>(){
{
put("UTF-8", "utf-8");
put("Windows", "MS932"); // Microsoft Windows CodePage 932
// ↑厳密に言うと Windows は「shift_jis」と完全な互換ではない.
// 今までスタンダードな表記法は「CP932」だったが、
// 「commons-net-3.3」では「MS932」でないとエラーになるようだ.
put("EUC-JP", "EUC-JP"); //
put("ASCII", "ISO-8859-1"); //
}
};
}
public void start(){
System.out.println("start( );");
repaint();
}
public void stop(){
System.out.println("stop( );");
}
public void destroy(){
System.out.println("destroy( );");
Write( );
}
public void Write() {
try {
int iListSize;
ObjectOutputStream oOOSSerial = new ObjectOutputStream(new FileOutputStream(fvsSerialFile));
oOOSSerial.writeObject(fvsSerialVersion);
oOOSSerial.writeBoolean(oMainPanelImp.cckHostPASVMode.isSelected( ));
oOOSSerial.writeObject(oMainPanelImp.ccbHostEncode.getSelectedObjects( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostName.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostPortNum.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostUserName.getText( ));
oOOSSerial.writeObject(new String(oMainPanelImp.cpfHostPassword.getPassword( )));
oOOSSerial.writeObject(oMainPanelImp.ccbFTPFileDataType.getSelectedObjects( ));
oOOSSerial.writeObject(oMainPanelImp.ctfLocalFolder.getText( ));
oOOSSerial.writeObject(oMainPanelImp.ctfHostFolder.getText( ));
iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
oOOSSerial.writeInt(iListSize );
for(int i=0; i<iListSize; i++ ){
oOOSSerial.writeObject(
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
}
iListSize = ((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getSize( );
oOOSSerial.writeInt(iListSize );
for(int i=0; i<iListSize; i++ ){
oOOSSerial.writeObject(
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
}
oOOSSerial.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:Write.");
PutMessage("FileNotFoundException:Write.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:Write.");
PutMessage("IOException:Write.\n");
}
}
public void Read() {
try {
ObjectInputStream oOISSerial = new ObjectInputStream(new FileInputStream(fvsSerialFile));
String vsVersion = (String)oOISSerial.readObject( );
if( fvsSerialVersion.compareTo("")==0){
// Non-Operation
}else if( fvsSerialVersion.compareTo(vsVersion)!=0){
System.out.println("Error:SerialVersion.");
PutMessage("Error:SerialVersion.\n");
}else{
int iListSize;
oMainPanelImp.cckHostPASVMode.setSelected(oOISSerial.readBoolean( ));
oMainPanelImp.ccbHostEncode.setSelectedItem(oOISSerial.readObject( ));
oMainPanelImp.ctfHostName.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostPortNum.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostUserName.setText((String)oOISSerial.readObject( ));
oMainPanelImp.cpfHostPassword.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ccbFTPFileDataType.setSelectedItem(oOISSerial.readObject( ));
oMainPanelImp.ctfLocalFolder.setText((String)oOISSerial.readObject( ));
oMainPanelImp.ctfHostFolder.setText((String)oOISSerial.readObject( ));
iListSize = oOISSerial.readInt( );
for(int i=0; i<iListSize; i++ ){
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).addElement(
oOISSerial.readObject( ));
}
iListSize = oOISSerial.readInt( );
for(int i=0; i<iListSize; i++ ){
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).addElement(
oOISSerial.readObject( ));
}
oOISSerial.close( );
}
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:Read.");
// PutMessage("FileNotFoundException:Read.\n");
// PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:Read.");
PutMessage("IOException:Read.\n");
} catch (ClassNotFoundException e) {
e.printStackTrace();
System.out.println("ClassNotFoundException:Read.");
PutMessage("ClassNotFoundException:Read.\n");
}
}
public void PutMessage(String vsMsg){
// System.out.println("PutMessage( );");
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の ctaMessage の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.ctaMessage.getParent( ).getParent( ));
oMainPanelImp.ctpBaseTabs.setSelectedComponent(oTabsSelectedComponent);
oMainPanelImp.ctaMessage.append(vsMsg);
}
public void FTPLogin() {
System.out.println("FTPLogin( );");
oMainPanelImp.ctaMessage.setText("");
lFTPPassiveMode = oMainPanelImp.cckHostPASVMode.isSelected( );
vsHostEncode =
da1CharEncodeSets.get((String)oMainPanelImp.ccbHostEncode.getSelectedItem());
Pattern pattern = Pattern.compile("( |\n)$");
vsHostName = oMainPanelImp.ctfHostName.getText();
matcher = pattern.matcher(vsHostName);
vsHostName = matcher.replaceAll("");
vsHostPortNum = oMainPanelImp.ctfHostPortNum.getText( );
matcher = pattern.matcher(vsHostPortNum);
vsHostPortNum = matcher.replaceAll("");
if(vsHostPortNum.isEmpty( )){ vsHostPortNum = "0"; }
iHostPortNum = Integer.parseInt(vsHostPortNum);
vsHostUserName = oMainPanelImp.ctfHostUserName.getText();
matcher = pattern.matcher(vsHostUserName);
vsHostUserName = matcher.replaceAll("");
vsHostPassword = String.valueOf(oMainPanelImp.cpfHostPassword.getPassword( ));
matcher = pattern.matcher(vsHostPassword);
vsHostPassword = matcher.replaceAll("");
System.out.println("MainAppFrameObj: "+
"vsHostEncode="+vsHostEncode+"; "+
"vsHostName="+vsHostName+"; "+
"iHostPortNum="+iHostPortNum+"; "+
"vsHostUserName="+vsHostUserName+"; "+
"vsHostPassword="+vsHostPassword+"; "+
"");
try {
client = new FTPClient();
String vsEncode = client.getControlEncoding();
System.out.println("MainAppFrameObj: "+
"vsEncode="+vsEncode+"; "+
"");
client.setControlEncoding(vsHostEncode);
// ↑ Host 側のキャラクター・セットを設定してやれば良いようだ.
System.out.println("Connect...");
client.connect(vsHostName, iHostPortNum);
System.out.println("Connected to Server:" + vsHostName + " on "+client.getRemotePort());
System.out.println(client.getReplyString());
client.login(vsHostUserName,vsHostPassword);
System.out.println(client.getReplyString());
lFTPConnection = true; // false; //
if (FTPReply.isPositiveCompletion(client.getReplyCode())) {
System.out.println("Success:Login.");
PutMessage("Success:Login.\n");
}else{
System.out.println("Error:FTP PositiveCompletion.");
PutMessage("Error:FTP PositiveCompletion.\n");
FTPLogout();
return;
}
if (lFTPPassiveMode) {
client.enterLocalPassiveMode();
System.out.println("PassiveMode = ON");
} else {
client.enterLocalActiveMode();
System.out.println("PassiveMode = OFF");
}
HostFileList("");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPLogin.");
PutMessage("NumberFormatException:FTPLogin.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPLogin.");
PutMessage("SocketException:FTPLogin.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPLogin.");
PutMessage("FileNotFoundException:FTPLogin.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPLogin.");
PutMessage("IOException:FTPLogin.\n");
}
}
public void FTPLogout() {
System.out.println("FTPLogout( );");
try {
lFTPConnection = false; // true; //
if( client!=null && client.isConnected( ) ){
client.disconnect( );
System.out.println("FTP Disconnect.");
PutMessage("FTP Disconnect.\n");
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPLogout.");
PutMessage("NumberFormatException:FTPLogout.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPLogout.");
PutMessage("SocketException:FTPLogout.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPLogout.");
PutMessage("FileNotFoundException:FTPLogout.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPLogout.");
PutMessage("IOException:FTPLogout.\n");
}
}
public void HostFileList(String vsTargetFile){
System.out.println("HostFileList( );");
if( client==null || ! client.isConnected( ) ){
oMainPanelImp.ctaMessage.append("Login されていません。\n");
return;
}
try {
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).removeAllElements( );
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.cltHostFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabsSelectedComponent);
if( client==null ){
System.out.println("if(client==null)");
PutMessage("if(client==null)\n");
return;
}
Pattern pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
System.out.println("vsTargetFile="+vsTargetFile+"; ");
if( vsTargetFile.compareTo("..")==0 ){
System.out.println("if( vsTargetFile.compareTo(..)==0 )");
vsTargetFile = "";
client.changeToParentDirectory();
}else{
if( vsTargetFile.compareTo("")!=0 ){
vsHostCurrent = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
}
// client.doCommand("CWD", vsHostCurrent);
client.changeWorkingDirectory(vsHostCurrent);
}
System.out.println(client.getReplyString());
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
String vsMsg = "Connection test => " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
PutMessage(vsMsg+"\n");
vsHostCurrent = client.printWorkingDirectory();
oMainPanelImp.ctfHostFolder.setText(vsHostCurrent);
System.out.println("vsHostCurrent="+vsHostCurrent+"; ");
if( vsHostCurrent.compareTo("/")!=0 ){
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
fvsPathListTag_Folder+"..");
}
SimpleDateFormat oSDF = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String vsElement = "";
String[] d1vsHostFile = new String[client.listFiles().length];
HashMap<String, String> da1PathListSets = new HashMap<String, String>( );
int i = 0;
for (FTPFile oFTPFile : client.listFiles()) {
String vsTimeStamp = fvsPathListTag_TimeStamp+oSDF.format(oFTPFile.getTimestamp().getTime());
String vsHostFile = oFTPFile.getName();
String vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
if( oFTPFile.isFile( ) ){
vsElement = fvsPathListTag_File;
}else if( oFTPFile.isDirectory( ) ){
vsElement = fvsPathListTag_Folder;
}
d1vsHostFile[i] = vsElement+vsHostFile;
da1PathListSets.put(d1vsHostFile[i], vsTimeStamp);
System.out.println(d1vsHostFile[i]);
System.out.println(vsTimeStamp);
i++;
}
FileSort(d1vsHostFile);
for ( i = 0; i<d1vsHostFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltHostFileList.getModel( )).addElement(
d1vsHostFile[i]);
String vsTimeStamp = da1PathListSets.get(d1vsHostFile[i]);
System.out.println(d1vsHostFile[i]);
System.out.println(vsTimeStamp);
char[] d1vcFileElement = d1vsHostFile[i].toCharArray();
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
// return;
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:HostFileList.");
PutMessage("NumberFormatException:HostFileList.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:HostFileList.");
PutMessage("SocketException:HostFileList.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:HostFileList.");
PutMessage("FileNotFoundException:HostFileList.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:HostFileList.");
PutMessage("IOException:HostFileList.\n");
}
}
public void LocalFileList(String vsTargetFile){
System.out.println("LocalFileList( );");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).removeAllElements( );
// JScrollPane には暗黙の子 JViewport が存在するようだ。
// つまり、この場合の JList の親は JViewport になり、
// JList の親の親が JScrollPane となる。
JScrollPane oTabsSelectedComponent = (JScrollPane)(oMainPanelImp.cltLocalFileList.getParent( ).getParent( ));
oMainPanelImp.ctpFileListTabs.setSelectedComponent(oTabsSelectedComponent);
Pattern pattern = Pattern.compile("( |\n)$");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
File oLocalCurrent = null;
System.out.println("vsTargetFile="+vsTargetFile+"; ");
try {
vsHostCurrent = "";
oLocalCurrent = new File(vsLocalCurrent,vsTargetFile);
vsLocalCurrent = oLocalCurrent.getCanonicalPath( );
if( vsTargetFile.compareTo("..")==0 ){
System.out.println("if( vsTargetFile.compareTo(..)==0 )");
vsTargetFile = "";
}
oMainPanelImp.ctfLocalFolder.setText(vsLocalCurrent);
System.out.println("vsLocalCurrent="+vsLocalCurrent+"; ");
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:LocalFileList.");
PutMessage("IOException:LocalFileList.\n");
oLocalCurrent = null;
}
if( oLocalCurrent!=null && oLocalCurrent.isDirectory( ) ){
pattern = Pattern.compile("^?(.:)(/|\\\\)$");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalCurrent);
System.out.println("pattern = Pattern.compile(^?(.:)(/|\\\\)$)");
if( ! matcher.find( ) ){
System.out.println("if( matcher.find( ) )");
// vsLocalCurrent = matcher.replaceAll("");
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
fvsPathListTag_Folder+"..");
}
String vsElement = "";
String[] d1vsLocalFile = new String[oLocalCurrent.listFiles().length];
int i = 0;
for (File oFile : oLocalCurrent.listFiles( )) {
String vsLocalFile = oFile.getName();
String vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
if(oFile.isFile()){
vsElement = fvsPathListTag_File;
}else if(oFile.isDirectory( )){
vsElement = fvsPathListTag_Folder;
}
d1vsLocalFile[i] = vsElement+vsLocalFile;
i++;
}
FileSort(d1vsLocalFile);
for ( i = 0; i<d1vsLocalFile.length; ++i) {
((DefaultListModel)oMainPanelImp.cltLocalFileList.getModel( )).addElement(
d1vsLocalFile[i]);
System.out.println(d1vsLocalFile[i]);
char[] d1vcFileElement = d1vsLocalFile[i].toCharArray( );
System.out.print("Hex = ");
for(int j = 0; j<d1vcFileElement.length; j++){
int k = d1vcFileElement[j];
if( k<0 ){ k = 65536+k; }
// ↑2の補数の負の値を正の値に変換している.
System.out.print(Integer.toHexString(k)+"; ");
}
System.out.println("");
}
}
}
public void FileSort(String[] d1vsFile){
System.out.println("Arrays.sort( );");
Arrays.sort(d1vsFile, new Comparator<String>() {
@Override
public int compare(String vs0, String vs1) {
// このソートを Windows 的な File 名のソート順にカスタマイズしている.
String vs, vsAscTab = new String(Character.toChars(0x09));
vs = vs0;
vs0 = vs.toUpperCase( )+vsAscTab+vs;
vs = vs1;
vs1 = vs.toUpperCase( )+vsAscTab+vs;
return vs0.compareTo(vs1);
}
});
}
public void FTPDownloadTransfer( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
String vsSaveBuf_HostFolder, vsSaveBuf_LocalFolder;
String vsHostPath, vsLocalPath;
vsSaveBuf_HostFolder = oMainPanelImp.ctfHostFolder.getText( );
vsSaveBuf_LocalFolder = oMainPanelImp.ctfLocalFolder.getText( );
int iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
for(int i = 0; i<iListSize; i++){
oMainPanelImp.ctfHostFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
oMainPanelImp.ctfLocalFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
System.out.println("FTPDownloadTransfer( ): "+
"oMainPanelImp.ctfHostFolder.getText="+oMainPanelImp.ctfHostFolder.getText()+"; "+
"oMainPanelImp.ctfHostFolder.getText="+oMainPanelImp.ctfLocalFolder.getText()+"; "+
"");
FTPDownload( );
}
oMainPanelImp.ctfHostFolder.setText(vsSaveBuf_HostFolder);
oMainPanelImp.ctfLocalFolder.setText(vsSaveBuf_LocalFolder);
System.out.println("FTPDownloadTransfer Completed.");
}
public void FTPDownload( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListTag_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListTag_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
if( vsTargetFile!=null ){
// vsLocalPath= vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPDownload: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPDownloadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
System.out.println("FTPDownload Completed.");
PutMessage("FTPDownload Completed.\n");
try {
client.changeWorkingDirectory(vsHostCurrent);
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPDownload.");
PutMessage("NumberFormatException:FTPDownload.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPDownload.");
PutMessage("SocketException:FTPDownload.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPDownload.");
PutMessage("FileNotFoundException:FTPDownload.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPDownload.");
PutMessage("IOException:FTPDownload.\n");
}
}
LocalFileList("");
lFTPBreak = false; // true; //
}
public void FTPDownloadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
System.out.println("FTPDownloadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && vsTargetFile.compareTo("")!=0 ){
FTPDownloadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent);
}else{
String vsHostPath = null;
try {
client.changeWorkingDirectory(vsHostCurrent);
System.out.println("client.changeWorkingDirectory(vsHostCurrent)");
// FTPFile[] d1oFTPFile = client.listFiles();
for (FTPFile oFTPFile : client.listFiles()) {
if( lFTPBreak ){
break;
}
String vsHostFile = oFTPFile.getName();
if( oFTPFile.isFile( ) ){
FTPDownloadFile( vsHostFile, vsHostCurrent, vsLocalCurrent);
}else if( oFTPFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsHostFile;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsHostFile;
System.out.println("FTPDownloadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
File oLocalPath = new File(vsLocalPath);
if( ! oLocalPath.exists( ) ){
oLocalPath.mkdir();
}
FTPDownloadFolder( "", vsHostPath, vsLocalPath );
client.changeWorkingDirectory(vsHostCurrent);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPDownloadFolder.");
PutMessage("NumberFormatException:FTPDownloadFolder.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPDownloadFolder.");
PutMessage("SocketException:FTPDownloadFolder.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPDownloadFolder.");
PutMessage("FileNotFoundException:FTPDownloadFolder.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPDownloadFolder.");
PutMessage("IOException:FTPDownloadFolder.\n");
}
}
}
public void FTPDownloadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent){
String vsMsg;
String vsLocalPath = null;
String vsHostPath = null;
FileOutputStream oFOS = null;
try{
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
vsLocalPath = vsLocalCurrent;
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
// client.changeWorkingDirectory(vsHostCurrent);
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPDownloadFile: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Download.
oFOS = new FileOutputStream(vsLocalPath);
client.retrieveFile(vsHostPath, oFOS);
oFOS.close();
PutMessage("vsHostPath = "+vsHostPath+";"+"\n");
PutMessage("vsLocalPath = "+vsLocalPath+";"+"\n");
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
vsMsg = "FTPDownloadFile Completed:Connection => " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPDownloadFile.");
PutMessage("NumberFormatException:FTPDownloadFile.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPDownloadFile.");
PutMessage("SocketException:FTPDownloadFile.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPDownloadFile.");
PutMessage("FileNotFoundException:FTPDownloadFile.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPDownloadFile.");
PutMessage("IOException:FTPDownloadFile.\n");
}
}
public void FTPUploadTransfer( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
String vsSaveBuf_HostFolder, vsSaveBuf_LocalFolder;
String vsHostPath, vsLocalPath;
vsSaveBuf_HostFolder = oMainPanelImp.ctfHostFolder.getText( );
vsSaveBuf_LocalFolder = oMainPanelImp.ctfLocalFolder.getText( );
int iListSize = ((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( );
for(int i = 0; i<iListSize; i++){
oMainPanelImp.ctfHostFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getElementAt(i));
oMainPanelImp.ctfLocalFolder.setText( (String)
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).getElementAt(i));
FTPUpload( );
}
oMainPanelImp.ctfHostFolder.setText(vsSaveBuf_HostFolder);
oMainPanelImp.ctfLocalFolder.setText(vsSaveBuf_LocalFolder);
System.out.println("FTPUploadTransfer Completed.");
}
public void FTPUpload( ){
if( client==null || ! client.isConnected( ) ){
PutMessage("Login されていません。\n");
return;
}
matcher = null;
Pattern pattern = null;
String vsTargetFile = null;
String vsHostPath = null;
pattern = Pattern.compile("( |\n)$");
vsHostCurrent = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostCurrent);
vsHostCurrent = matcher.replaceAll("");
vsLocalCurrent = oMainPanelImp.ctfLocalFolder.getText();
matcher = pattern.matcher(vsLocalCurrent);
vsLocalCurrent = matcher.replaceAll("");
String vsLocalPath = vsLocalCurrent;
pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
try {
File oLocalCurrent;
File oLocalPath = new File(vsLocalPath);
if( oLocalPath.isFile( ) ){
vsTargetFile = oLocalPath.getName( );
vsLocalCurrent = oLocalPath.getParent( );
oLocalCurrent = new File(vsLocalCurrent);
vsLocalCurrent = oLocalCurrent.getCanonicalPath();
}else if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^"+fvsPathListTag_File);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
pattern = Pattern.compile("^"+fvsPathListTag_Folder);
matcher = pattern.matcher(vsTargetFile);
vsTargetFile = matcher.replaceAll("");
if(matcher.find()){
System.out.println("if(matcher.find( ))");
vsLocalPath = vsLocalCurrent+(vsLocalCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsTargetFile = "";
}
}else{
vsTargetFile = "";
}
} catch (IOException e) {
// TODO 自動生成された catch ブロック
e.printStackTrace();
System.out.println("IOException:FTPUpload.");
PutMessage("IOException:FTPUpload.\n");
vsTargetFile = null;
}
if( vsTargetFile!=null ){
System.out.println("FTPUpload: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPatht="+vsLocalPath+"; "+
"");
FTPUploadFolder( vsTargetFile, vsHostCurrent, vsLocalCurrent );
System.out.println("FTPUpload Completed.");
PutMessage("FTPUpload Completed.\n");
try {
client.changeWorkingDirectory(vsHostCurrent);
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPUpload.");
PutMessage("NumberFormatException:FTPUpload.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPUpload.");
PutMessage("SocketException:FTPUpload.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPUpload.");
PutMessage("FileNotFoundException:FTPUpload.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUpload.");
PutMessage("IOException:FTPUpload.\n");
}
}
HostFileList("");
lFTPBreak = false; // true; //
}
public void FTPUploadFolder( String vsTargetFile, String vsHostCurrent, String vsLocalCurrent ){
System.out.println("FTPUploadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"");
if( vsTargetFile!=null && vsTargetFile.compareTo("")!=0 ){
FTPUploadFile( vsTargetFile, vsHostCurrent, vsLocalCurrent);
}else{
String vsHostPath = null;
try {
File oLocalCurrent = new File(vsLocalCurrent);
System.out.println("oLocalCurrent = new File(vsLocalCurrent)");
for (File oFile : oLocalCurrent.listFiles()) {
if( lFTPBreak ){
break;
}
String vsLocalFile = oFile.getName();
if( oFile.isFile( ) ){
FTPUploadFile( vsLocalFile, vsHostCurrent, vsLocalCurrent);
}else if( oFile.isDirectory( ) ){
String vsLocalPath = vsLocalCurrent;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsLocalFile;
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsLocalFile;
System.out.println("FTPUploadFolder: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
try {
// client.changeWorkingDirectory(vsHostPath);
System.out.println("client.makeDirectory(vsHostPath).");
client.makeDirectory(vsHostPath);
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUploadFolder");
PutMessage("IOException:FTPUploadFolder.\n");
}
FTPUploadFolder( "", vsHostPath, vsLocalPath );
client.changeWorkingDirectory(vsHostCurrent);
}
}
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPUploadFolder.");
PutMessage("NumberFormatException:FTPUploadFolder.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPUploadFolder.");
PutMessage("SocketException:FTPUploadFolder.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPUploadFolder.");
PutMessage("FileNotFoundException:FTPUploadFolder.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUploadFolder.");
PutMessage("IOException:FTPUploadFolder.\n");
}
}
}
public void FTPUploadFile(String vsTargetFile,String vsHostCurrent,String vsLocalCurrent){
String vsMsg;
String vsLocalPath = null;
String vsHostPath = null;
FileInputStream oFIS = null;
Pattern pattern = Pattern.compile("(\\\\)");
// ↑この「\\\\」は内部的に「\\」の文字列となり、
// 正規表現では「\」の文字と解釈される.
vsLocalPath = vsLocalCurrent;
matcher = pattern.matcher(vsLocalPath);
vsLocalPath = matcher.replaceAll("/");
vsHostPath = vsHostCurrent+(vsHostCurrent.endsWith("/") ? "" : "/")+vsTargetFile;
vsLocalPath = vsLocalPath+(vsLocalPath.endsWith("/") ? "" : "/")+vsTargetFile;
System.out.println("FTPUploadFile: "+
"vsTargetFile="+vsTargetFile+"; "+
"vsHostCurrent="+vsHostCurrent+"; "+
"vsLocalCurrent="+vsLocalCurrent+"; "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"");
lFTPTransfer_Binary = false; // true; //
if( 0==fvsFTPTransfer_Binary.compareTo(
(String)oMainPanelImp.ccbFTPFileDataType.getSelectedItem( )) ){
lFTPTransfer_Binary = true; // false; //
}
try{
if(lFTPTransfer_Binary){
client.setFileType(FTP.BINARY_FILE_TYPE);
System.out.println("Transfer:Binary.");
}else{
client.setFileType(FTP.ASCII_FILE_TYPE);
System.out.println("Transfer:ASCII.");
}
// FTP Upload.
oFIS = new FileInputStream(vsLocalPath);
client.storeFile(vsHostPath, oFIS);
oFIS.close();
PutMessage("FTPUploadFile: "+
"vsHostPath="+vsHostPath+"; "+
"vsLocalPath="+vsLocalPath+"; "+
"\n");
lFTPConnection = FTPReply.isPositiveCompletion(client.getReplyCode());
vsMsg = "FTPUploadFile Completed:Connection = " + (lFTPConnection ? "OK" : "NG")+".";
System.out.println(vsMsg);
PutMessage(vsMsg+"\n");
} catch (NumberFormatException e) {
e.printStackTrace();
System.out.println("NumberFormatException:FTPUploadFile.");
PutMessage("NumberFormatException:FTPUploadFile.\n");
PutMessage("FTPポートの値が数値ではありません。\n");
} catch (SocketException e) {
e.printStackTrace();
System.out.println("SocketException:FTPUploadFile.");
PutMessage("SocketException:FTPUploadFile.\n");
PutMessage("Socket通信に失敗しました。\n");
} catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("FileNotFoundException:FTPUploadFile.");
PutMessage("FileNotFoundException:FTPUploadFile.\n");
PutMessage("ファイルが見つかりません。\n");
} catch (IOException e) {
e.printStackTrace();
System.out.println("IOException:FTPUploadFile.");
PutMessage("IOException:FTPUploadFile.\n");
}
}
class MainPanelImplementationObj extends MainPanelDesign {
long ilDoubleClickedIntervalMax = 250; // 350; 300;
// volatile:最適化の抑制.
volatile byte ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
Thread oThread_HostFileList_CbtMouseMouseDoubleClicked;
Runnable oRunner_HostFileList_CbtMouseMouseDoubleClicked;
// volatile:最適化の抑制.
volatile byte ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
Thread oThread_LocalFileList_CbtMouseMouseDoubleClicked;
Runnable oRunner_LocalFileList_CbtMouseMouseDoubleClicked;
MainPanelImplementationObj(){
super( );
oThread_HostFileList_CbtMouseMouseDoubleClicked = new Thread(
oRunner_HostFileList_CbtMouseMouseDoubleClicked = new Runnable( ) {
@Override
public synchronized void run() {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_HostFileList_CbtMouseMouseDoubleClicked==2 ){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
HostFileList_CbtMouseMouseClicked( );
}
}
}
}
);
oThread_HostFileList_CbtMouseMouseDoubleClicked.start( );
oThread_LocalFileList_CbtMouseMouseDoubleClicked = new Thread(
oRunner_LocalFileList_CbtMouseMouseDoubleClicked = new Runnable( ) {
@Override
public synchronized void run() {
System.out.println("run.");
boolean lInterrupted = false; // true; //
while(true){
try {
wait( );
// ↑メソッドを synchronized 指定するか、
// synchronized(自分のインスタンス) ブロックで囲うかしないと
// 実行時に「IllegalMonitorStateException」が発生する。
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("wait:End.");
lInterrupted = false; // true; //
try {
Thread.sleep(ilDoubleClickedIntervalMax);
} catch (InterruptedException e) {
// e.printStackTrace();
System.out.println("sleep:InterruptedException.");
lInterrupted = true; // false; //
}
System.out.println("sleep:End.");
if( ! lInterrupted &&
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked==2 ){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
LocalFileList_CbtMouseMouseClicked( );
}
}
}
}
);
oThread_LocalFileList_CbtMouseMouseDoubleClicked.start( );
}
@Override
void HostLogin_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogin_CbtMouseMouseReleased.");
oMainApp.FTPLogin( );
}
@Override
void HostLogout_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostLogout_CbtMouseMouseReleased.");
oMainApp.FTPLogout( );
}
@Override
void FTPFileList_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPFileList_CbtMouseMouseReleased.");
Pattern pattern = Pattern.compile("( |\n)$");
vsHostFolder = oMainPanelImp.ctfHostFolder.getText();
matcher = pattern.matcher(vsHostFolder);
vsHostFolder = matcher.replaceAll("");
JScrollPane oTabsSelectedComponent = (JScrollPane)oMainPanelImp.ctpFileListTabs.getSelectedComponent( );
System.out.println("oTabsSelectedComponent = "+oTabsSelectedComponent);
System.out.println("oTabsSelectedComponent.getViewport() = "+oTabsSelectedComponent.getViewport());
System.out.println("cltLocalFileList.getParent() = "+oMainPanelImp.cltLocalFileList.getParent());
System.out.println("cltLocalFileList.getParent().getParent() = "+oMainPanelImp.cltLocalFileList.getParent().getParent());
// JScrollPane には暗黙の子 JViewport が存在し、
// 「JScrollPane.getViewport( ) 」で(暗黙の子) JViewport のインスタンスを取得できる。
// つまり、この場合の JList の親は JViewport となる。
// ちなみに、この場合の JList の親の親が JScrollPane となる。
if( lFTPConnection &&
oTabsSelectedComponent.getViewport()==oMainPanelImp.cltHostFileList.getParent( ) ){
//
}
if( oTabsSelectedComponent.getViewport()==oMainPanelImp.cltLocalFileList.getParent( ) ){
//
}
}
@Override
void FTPDownload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPDownload_CbtMouseMouseReleased.");
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPDownload( );
}else{
FTPDownloadTransfer( );
}
}
@Override
void FTPUpload_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPUpload_CbtMouseMouseReleased.");
if( 0==((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).getSize( ) ){
FTPUpload( );
}else{
FTPUploadTransfer( );
}
}
void HostFileList_CbtMouseMouseClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtMouseMouseClicked.");
}
void HostFileList_CbtMouseMouseDoubleClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtMouseMouseDoubleClicked.");
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltHostFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltHostFileList.getSelectedValue();
pattern = Pattern.compile("^("+fvsReg_PathListTag_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
HostFileList(vsTargetFile);
}
}else{
vsTargetFile = null;
PutMessage("HostFileList で項目が選択せれていません.\n");
}
}
@Override
void HostFileList_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CbtNativeMouseMousePressed");
if(oThread_HostFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.TIMED_WAITING){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 3;
oThread_HostFileList_CbtMouseMouseDoubleClicked.interrupt();
}else{
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 1;
}
System.out.println("ibCnt_HostFileList_CbtMouseMouseDoubleClicked="+ibCnt_HostFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void HostFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:HostFileList_CltNativeMouseMouseReleased.");
if(ibCnt_HostFileList_CbtMouseMouseDoubleClicked==3){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 0;
HostFileList_CbtMouseMouseDoubleClicked( );
}else if(oThread_HostFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.WAITING){
ibCnt_HostFileList_CbtMouseMouseDoubleClicked = 2;
synchronized(oRunner_HostFileList_CbtMouseMouseDoubleClicked) {
oRunner_HostFileList_CbtMouseMouseDoubleClicked.notify();
// ↑ synchronized(自分のインスタンス) ブロックで囲わないとないと
// 実行時に「IllegalMonitorStateException」が発生する。
// ここ(this)は他人なので、ここのメソッドを synchronized 指定してもダメ。
}
}
System.out.println("ibCnt_HostFileList_CbtMouseMouseDoubleClicked="+ibCnt_HostFileList_CbtMouseMouseDoubleClicked+"; ");
}
void LocalFileList_CbtMouseMouseClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtMouseMouseClicked.");
}
void LocalFileList_CbtMouseMouseDoubleClicked( ) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtMouseMouseDoubleClicked.");
Pattern pattern = null;
String vsTargetFile = null;
if( ! oMainPanelImp.cltLocalFileList.isSelectionEmpty() ){
vsTargetFile = (String)oMainPanelImp.cltLocalFileList.getSelectedValue();
pattern = Pattern.compile("^("+fvsReg_PathListTag_Folder+")");
matcher = pattern.matcher(vsTargetFile);
if(matcher.find()){
vsTargetFile = matcher.replaceAll("");
System.out.println("vsTargetFile = "+vsTargetFile+"; ");
LocalFileList(vsTargetFile);
}
}else{
vsTargetFile = null;
PutMessage("LocalFileList で項目が選択せれていません.\n");
}
}
@Override
void LocalFileList_CbtNativeMouseMousePressed(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CbtNativeMouseMousePressed");
if(oThread_LocalFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.TIMED_WAITING){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 3;
oThread_LocalFileList_CbtMouseMouseDoubleClicked.interrupt();
}else{
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 1;
}
System.out.println("ibCnt_LocalFileList_CbtMouseMouseDoubleClicked="+ibCnt_LocalFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void LocalFileList_CltNativeMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:LocalFileList_CltNativeMouseMouseReleased");
if(ibCnt_LocalFileList_CbtMouseMouseDoubleClicked==3){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 0;
LocalFileList_CbtMouseMouseDoubleClicked( );
}else if(oThread_LocalFileList_CbtMouseMouseDoubleClicked.getState()==Thread.State.WAITING){
ibCnt_LocalFileList_CbtMouseMouseDoubleClicked = 2;
synchronized(oRunner_LocalFileList_CbtMouseMouseDoubleClicked) {
oRunner_LocalFileList_CbtMouseMouseDoubleClicked.notify();
// ↑ synchronized(自分のインスタンス) ブロックで囲わないとないと
// 実行時に「IllegalMonitorStateException」が発生する。
// ここ(this)は他人なので、ここのメソッドを synchronized 指定してもダメ。
}
}
System.out.println("ibCnt_LocalFileList_CbtMouseMouseDoubleClicked="+ibCnt_LocalFileList_CbtMouseMouseDoubleClicked+"; ");
}
@Override
void SetupFileList_HostFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_HostFolder_CbtMouseMouseReleased.");
HostFileList("");
}
@Override
void SetupFileList_LocalFolder_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:SetupFileList_LocalFolder_CbtMouseMouseReleased.");
LocalFileList("");
}
@Override
void FTPBreak_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:FTPBreak_CbtMouseMouseReleased.");
lFTPBreak = true; // false; //
}
@Override
void TransferListEntry_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:TransferListEntry_CbtMouseMouseReleased.");
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).addElement(
ctfHostFolder.getText( ));
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).addElement(
ctfLocalFolder.getText( ));
}
@Override
void TransferListDelete_CbtMouseMouseReleased(MouseEvent event) {
System.out.println("MainPanelImplementationObj:MouseEvent:TransferListDelete_CbtMouseMouseReleased.");
int iSelectedIndex = -1;
JScrollPane oTabsSelectedComponent = (JScrollPane)oMainPanelImp.ctpTransferListTabs.getSelectedComponent( );
// JScrollPane には暗黙の子 JViewport が存在し、
// 「JScrollPane.getViewport( ) 」で(暗黙の子) JViewport のインスタンスを取得できる。
// つまり、この場合の JList の親は JViewport となる。
// ちなみに、この場合の JList の親の親が JScrollPane となる。
if( oTabsSelectedComponent.getViewport( )==oMainPanelImp.cltHostTransferList.getParent( ) ){
System.out.println("if(oTabsSelectedComponent.getViewport( )==cltHostTransferList.getParent( )).");
if( oMainPanelImp.cltHostTransferList.isSelectionEmpty( ) ){
PutMessage("cltHostTransferList:表示されているタブに選択されている項目がありません。\n");
}else{
iSelectedIndex = oMainPanelImp.cltHostTransferList.getSelectedIndex( );
}
}
if( oTabsSelectedComponent.getViewport( )==oMainPanelImp.cltLocalTransferList.getParent( ) ){
System.out.println("(oTabsSelectedComponent.getViewport( )==cltLocalTransferList.getParent( )).");
if( oMainPanelImp.cltLocalTransferList.isSelectionEmpty( ) ){
PutMessage("cltLocalTransferList:表示されているタブに選択されている項目がありません。\n");
}else{
iSelectedIndex = oMainPanelImp.cltLocalTransferList.getSelectedIndex( );
}
}
System.out.println("iSelectedIndex="+iSelectedIndex+"; ");
if( 0<=iSelectedIndex ){
System.out.println("if( 0<=iSelectedIndex )");
((DefaultListModel)oMainPanelImp.cltHostTransferList.getModel( )).remove(iSelectedIndex);
((DefaultListModel)oMainPanelImp.cltLocalTransferList.getModel( )).remove(iSelectedIndex);
}
}
}
static class MainAppFrameObj extends JFrame implements Runnable {
// JApplet oApplet;
Thread oAppThread;
public MainAppFrameObj( ) {
super("Application frame.");
//setVisible(false);
System.out.println("Construct:Application frame window.");
// oApplet = oEntApplet; // new JAppletcation();
addWindowListener(
new WindowAdapter(){
public void windowClosing(WindowEvent event){
// ユーザーがウインドウを閉じようとした時].
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosing.");
oMainApp.FTPLogout();
Close();
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowClosed(WindowEvent event){
// ウインドウが閉じた時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowClosed.");
}
}
}
);
addWindowListener(
new WindowAdapter(){
public void windowDeiconified(WindowEvent event){
// ウィンドウが最小化された状態から通常の状態に変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("MainAppFrameObj:WindowEvent:windowDeiconified.");
oMainApp.repaint();
}
}
}
);
addComponentListener(
new ComponentAdapter(){
public void componentResized(ComponentEvent event){
// コンポーネントのサイズが変更された時.
Object oSource = event.getSource();
if (oSource == MainAppFrameObj.this){
System.out.println("ComponentEvent:componentResized.");
System.out.println("MainAppFrameObj: "+
"width="+Integer.toString(MainAppFrameObj.this.getSize( ).width)+"; "+
"Height="+Integer.toString(MainAppFrameObj.this.getSize( ).height)+"; "+
"");
oMainApp.repaint();
}
}
}
);
getContentPane().add(oMainApp,"Center");
oAppThread= new Thread(this);
}
public synchronized void setPreSize(Dimension oSize){
// dispose();
getContentPane().setPreferredSize(oSize);
pack();
setVisible(true);
requestFocus();
}
public synchronized void run(){
System.out.println("Open:Application frame window.");
oMainApp.init();
oMainApp.start();
oMainApp.repaint();
try{
wait();
}
catch(InterruptedException e){
e.printStackTrace();
}
oMainApp.stop();
oMainApp.destroy();
oAppThread = null;
}
public synchronized void Close(){
System.out.println("Close:Application frame window.");
dispose();
notify();
}
}
}
|
|