//--------------------------------------------------------------------------- // FTP接続パラメータセット // // 説明: // 引数: // 戻値: 0: 設定完了 -1:設定失敗 //--------------------------------------------------------------------------- public int SetUpClient() { const string INI_SECTION = "FTP"; const string INI_FTP_SERVER_KEY = "FtpServer"; const string INI_FTP_SERVER_PORT_KEY = "FtpServerPort"; const string INI_FTP_LOGIN_USER_NAME = "FtpUserName"; const string INI_FTP_LOGIN_PASSWORD = "******"; string strReadStr1, strReadStr2; int mReadvalue; // INIファイルからFTPサーバー情報とアクセスパラメータを読み込み strReadStr1 = ""; strReadStr1 = IniFile.GetValueString(INI_SECTION, INI_FTP_SERVER_KEY); if (strReadStr1 != "") { _Client.Host = strReadStr1; } else { return(-1); } mReadvalue = 0; mReadvalue = IniFile.GetValueInt(INI_SECTION, INI_FTP_SERVER_PORT_KEY); if (mReadvalue != 0) { _Client.Port = mReadvalue; } else { return(-1); } strReadStr1 = ""; strReadStr2 = ""; strReadStr1 = IniFile.GetValueString(INI_SECTION, INI_FTP_LOGIN_USER_NAME); strReadStr2 = IniFile.GetValueString(INI_SECTION, INI_FTP_LOGIN_PASSWORD); if (strReadStr1 != "" && strReadStr2 != "") { _Client.Credentials = new NetworkCredential(strReadStr1, strReadStr2); } else { return(-1); } // 要求の完了後に接続を閉じる _Client.SocketKeepAlive = false; // Explicit設定 _Client.EncryptionMode = FtpEncryptionMode.None; //none // プロトコルはTls _Client.SslProtocols = SslProtocols.None; //tls // 接続タイムアウトを5秒に設定 _Client.ConnectTimeout = 5000; // 証明書の内容を確認しない _Client.ValidateCertificate += new FtpSslValidation(OnValidateCertificate); _isCientSetupOK = true; return(0); }
//--------------------------------------------------------------------------- // 転送ファイル有無と一覧作成 // // 説明: // 引数: // 戻値: ファイル一覧 //--------------------------------------------------------------------------- public static List<string> GetUploadFilePathList() { List<string> Paths = new List<string>(); string strFileName = ""; FileInfo file; long lTotalfileSize = 0; try { // ファイル出力先 string strCsvPath = IniFile.GetValueString("OutputCSVFile", "OutputCSVFolderPath"); // 最大アップロード容量 long lLimitSize = IniFile.GetValueInt("FTP", "FtpFopFileSizeLimit"); ; if(Directory.Exists(strCsvPath) == false) { return Paths; } // 出力トレンドファイル有無の確認 string[] arryTrend = Directory.GetFiles(strCsvPath, "*_TREND.csv"); string[] arryEvent = Directory.GetFiles(strCsvPath, "*_EVENT.csv"); if (arryTrend.Length == 0 && arryEvent.Length == 0) { return Paths; } int nTrendCnt, nEventCnt; bool isNonTrendFile, isNonEventFile; nTrendCnt = 0; nEventCnt = 0; isNonTrendFile = false; isNonEventFile = false; // 1つずつファイルの容量を確認し、制限内であればファイルの名前とパスを // リストに加えていく while (true) { if (arryTrend.Length > nTrendCnt) { strFileName = arryTrend[nTrendCnt]; file = new FileInfo(strFileName); if ((lTotalfileSize + file.Length) < lLimitSize) { Paths.Add(Path.GetFileName(strFileName)); Paths.Add(strFileName); nTrendCnt++; } lTotalfileSize += file.Length; } else { isNonTrendFile = true; } if (arryEvent.Length > nEventCnt) { strFileName = arryEvent[nEventCnt]; file = new FileInfo(strFileName); if ((lTotalfileSize + file.Length) < lLimitSize) { Paths.Add(Path.GetFileName(strFileName)); Paths.Add(strFileName); nEventCnt++; } lTotalfileSize += file.Length; } else { isNonEventFile = true; } if (lTotalfileSize >= lLimitSize) { break; } if(isNonTrendFile == true && isNonEventFile == true) { break; } } } catch(Exception ex) { } return Paths; }