private async Task OpenFolderAsync(TreeViewItem itemToOpen) { itemToOpen.Items.Clear(); string[] folders = await FtpUtils.FtpListFilesFoldersAsync(itemToOpen.Tag as string, Credential); foreach (string s in folders) { if (string.IsNullOrWhiteSpace(s)) { continue; } if (s.Equals(".") || s.Equals("..")) { continue; } if (!Path.HasExtension(s)) { TreeViewItem item = new TreeViewItem() { Header = s, Tag = (itemToOpen.Tag as string) + s + "/" }; item.MouseDoubleClick += Item_MouseDoubleClick; itemToOpen.Items.Add(item); } } }
public override void Export(TextAsset packageJsonAsset, Action success, Action fail) { var writePass = writePassword; writePassword = string.Empty; EditorUtility.SetDirty(this); AssetDatabase.Refresh(); ExecuteAction(() => { var packageJson = JsonUtility.FromJson <PackageJson>(packageJsonAsset.text); var unityPackageFile = GetTempUnityPackagePath(); ExportUnityPackage(packageJsonAsset, unityPackageFile, () => { writePassword = writePass; EditorUtility.SetDirty(this); AssetDatabase.Refresh(); var data = new FtpData { Url = url, User = user, Password = writePassword, LocalFile = unityPackageFile, PackageName = packageJson.name, PackageVersion = packageJson.version, UnityPackageName = name, }; FtpUtils.Upload(data, success, fail); }, fail); }, fail); }
private async void CreateFolder(string folderName) { if (string.IsNullOrWhiteSpace(folderName)) { MessageBox.Show("Invalid folder name"); return; } List <char> invalidChars = Path.GetInvalidFileNameChars().ToList(); invalidChars.AddRange(Path.GetInvalidPathChars().ToList()); foreach (char c in invalidChars) { if (folderName.Contains(c)) { MessageBox.Show(string.Format("value '{0}' is invalid for name", c)); return; } } CreatingFolderTextBlock.Visibility = Visibility.Visible; try { await FtpUtils.FtpMakeFolderAsync(string.Format("{0}{1}", FTPPath, folderName), Credential); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } FTPReturnFolderName = folderName; FTPReturnPath = string.Format("{0}{1}/", FTPPath, folderName); DialogResult = true; Close(); }
public override void Import(TextAsset packageJsonAsset, Action success, Action fail) { ExecuteAction(() => { var packageJson = JsonUtility.FromJson <PackageJson>(packageJsonAsset.text); var unityPackageFile = GetTempUnityPackagePath(); var data = new FtpData { Url = url, User = user, Password = readPassword, LocalFile = unityPackageFile, PackageName = packageJson.name, PackageVersion = packageJson.version, UnityPackageName = name, }; FtpUtils.Download(data, () => { AssetDatabase.ImportPackage(unityPackageFile, true); success(); }, fail); }, fail); }
public override async Task RunTask() { NetworkCredential networkCredential = new NetworkCredential(AutomationSettings.BigmodsUsername, AutomationSettings.BigmodsPassword); string serverPath = string.Format("{0}{1}", PrivateStuff.BigmodsFTPUsersRoot, WoTOnlineFolderVersion); Logging.Info("Checking if {0} already exists on the server in folder {1}", ZipFileName, WoTOnlineFolderVersion); string[] listOfFilesOnServer = await FtpUtils.FtpListFilesFoldersAsync(serverPath, networkCredential); int duplicateIncriment = 1; string nameWithNoExtension = Path.GetFileNameWithoutExtension(ZipFileName); string extension = Path.GetExtension(ZipFileName); string newFilename = ZipFileName; while (listOfFilesOnServer.Contains(newFilename)) { Logging.Info("Filename already exists on server, giving it a unique name"); newFilename = string.Format("{0}_{1}{2}", nameWithNoExtension, duplicateIncriment++.ToString(), extension); Logging.Info("Propose {0}", newFilename); } ZipFileName = newFilename; using (WebClient = new WebClient { Credentials = networkCredential }) { string uploadUrl = string.Format("{0}/{1}", serverPath, ZipFileName); Logging.Info(Logfiles.AutomationRunner, "Uploading package"); Logging.Debug(Logfiles.AutomationRunner, "Upload zip url = {0}, file = {1}", uploadUrl, FilePath); //https://stackoverflow.com/questions/2953403/c-sharp-passing-method-as-the-argument-in-a-method if (DatabaseAutomationRunner != null) { WebClient.UploadProgressChanged += DatabaseAutomationRunner.UploadProgressChanged; WebClient.UploadFileCompleted += DatabaseAutomationRunner.UploadFileCompleted; } try { await WebClient.UploadFileTaskAsync(uploadUrl, FilePath); DatabasePackage.UpdatePackageName(ZipFileName); FtpUtils.TriggerMirrorSyncAsync(); TransferSuccess = true; } catch (OperationCanceledException) { } catch (Exception ex) { Logging.Exception(ex.ToString()); } finally { if (DatabaseAutomationRunner != null) { WebClient.UploadProgressChanged -= DatabaseAutomationRunner.UploadProgressChanged; WebClient.UploadFileCompleted -= DatabaseAutomationRunner.UploadFileCompleted; } } } }
public override async Task RunTask() { using (WebClient = new WebClient { Credentials = new NetworkCredential(AutomationSettings.BigmodsUsername, AutomationSettings.BigmodsPassword) }) { string serverPath = string.Format("{0}{1}/{2}", PrivateStuff.BigmodsFTPUsersRoot, WoTOnlineFolderVersion, DatabasePackage.ZipFile); Logging.Info(Logfiles.AutomationRunner, "Downloading package"); Logging.Debug(Logfiles.AutomationRunner, "Download zip url = {0}, file = {1}", serverPath, FilePath); //https://stackoverflow.com/questions/2953403/c-sharp-passing-method-as-the-argument-in-a-method if (DatabaseAutomationRunner != null) { WebClient.DownloadProgressChanged += DatabaseAutomationRunner.DownloadProgressChanged; WebClient.DownloadFileCompleted += DatabaseAutomationRunner.DownloadFileCompleted; } try { if (DatabaseAutomationRunner != null) { if (DatabaseAutomationRunner.DownloadProgressChanged != null) { long filesize = await FtpUtils.FtpGetFilesizeAsync(serverPath, WebClient.Credentials); DatabaseAutomationRunner.ProgressChanged.Invoke(null, new ProgressChangedEventArgs(69, filesize)); } } await WebClient.DownloadFileTaskAsync(serverPath, FilePath); TransferSuccess = true; } catch (OperationCanceledException) { } catch (Exception ex) { Logging.Exception(ex.ToString()); } finally { if (DatabaseAutomationRunner != null) { WebClient.DownloadProgressChanged -= DatabaseAutomationRunner.DownloadProgressChanged; WebClient.DownloadFileCompleted -= DatabaseAutomationRunner.DownloadFileCompleted; } } } }
private async void Client_DownloadUploadFileCompleted(object sender, System.ComponentModel.AsyncCompletedEventArgs e) { if (e.Cancelled) { Logging.Editor("FTP upload or download cancel detected from UI thread, handling"); switch (TransferMode) { case EditorTransferMode.UploadZip: case EditorTransferMode.UploadMedia: Logging.Editor("Deleting file on server"); await FtpUtils.FtpDeleteFileAsync(CompleteFTPPath, Credential); break; case EditorTransferMode.DownloadZip: Logging.Editor("Deleting file on disk"); File.Delete(ZipFilePathDisk); break; } Close(); } }
private async void RelhaxWindow_Loaded(object sender, RoutedEventArgs e) { if (EditorSettings == null) { throw new NullReferenceException(); } //init timer timer = new DispatcherTimer(TimeSpan.FromSeconds(1), DispatcherPriority.Background, Timer_Elapsed, this.Dispatcher) { IsEnabled = false }; //setup UI based on transfer type OpenFodlerButton.Visibility = (TransferMode == EditorTransferMode.DownloadZip) ? Visibility.Visible : Visibility.Hidden; OpenFileButton.Visibility = (TransferMode == EditorTransferMode.DownloadZip) ? Visibility.Visible : Visibility.Hidden; //set log based on file upload type switch (TransferMode) { case EditorTransferMode.UploadZip: ProgressBody.Text = string.Format("Uploading {0} to FTP folder {1}", Path.GetFileName(ZipFilePathDisk), WoTModpackOnlineFolderVersion); break; case EditorTransferMode.UploadMedia: ProgressBody.Text = string.Format("Uploading {0} to FTP folder Medias/...", ZipFileName); break; case EditorTransferMode.DownloadZip: ProgressBody.Text = string.Format("Downloading {0} from FTP folder {1}", Path.GetFileName(ZipFilePathDisk), WoTModpackOnlineFolderVersion); break; } //set initial text(s) ProgressHeader.Text = string.Format("{0} 0 kb of 0 kb", TransferMode.ToString()); CompleteFTPPath = string.Format("{0}{1}", ZipFilePathOnline, ZipFileName); using (client = new WebClient() { Credentials = Credential }) { switch (TransferMode) { case EditorTransferMode.UploadZip: case EditorTransferMode.UploadMedia: //before uploading, make sure it doesn't exist first (zipfile or media) ProgressHeader.Text = "Checking if file exists on server..."; Logging.Editor("Checking if {0} already exists on the server in folder {1}", LogLevel.Info, ZipFileName, WoTModpackOnlineFolderVersion); string[] listOfFilesOnServer = await FtpUtils.FtpListFilesFoldersAsync(ZipFilePathOnline, Credential); if (listOfFilesOnServer.Contains(ZipFileName) && MessageBox.Show("File already exists, overwrite?", "", MessageBoxButton.YesNo) != MessageBoxResult.Yes) { Logging.Editor("DOES exist and user said don't overwrite, aborting"); ProgressHeader.Text = "Canceled"; return; } //attach upload event handlers client.UploadProgressChanged += Client_UploadProgressChanged; client.UploadFileCompleted += Client_DownloadUploadFileCompleted; //run the FTP upload Logging.Editor("Starting FTP upload of {0} from folder {1}", LogLevel.Info, ZipFileName, WoTModpackOnlineFolderVersion); try { await client.UploadFileTaskAsync(CompleteFTPPath, ZipFilePathDisk); Logging.Editor("FTP upload complete of {0}", LogLevel.Info, ZipFileName); //run upload event handler OnEditorUploadDownloadClosed?.Invoke(this, new EditorTransferEventArgs() { Package = PackageToUpdate, UploadedFilename = ZipFileName, UploadedFilepathOnline = ZipFilePathOnline, TransferMode = this.TransferMode }); DeleteFileButton.IsEnabled = true; if (TransferMode == EditorTransferMode.UploadZip && EditorSettings.DeleteUploadLocallyUponCompletion) { DeleteFileButton_Click(null, null); } } catch (Exception ex) { Logging.Editor("FTP UPLOAD Failed"); Logging.Editor(ex.ToString()); } finally { CancelButton.IsEnabled = false; } break; case EditorTransferMode.DownloadZip: //attach download event handlers client.DownloadProgressChanged += Client_DownloadProgressChanged; client.DownloadFileCompleted += Client_DownloadUploadFileCompleted; //run the FTP download Logging.Editor("Starting FTP download of {0} from folder {1}", LogLevel.Info, ZipFileName, WoTModpackOnlineFolderVersion); try { FTPDownloadFilesize = await FtpUtils.FtpGetFilesizeAsync(CompleteFTPPath, Credential); await client.DownloadFileTaskAsync(CompleteFTPPath, ZipFilePathDisk); Logging.Editor("FTP download complete of {0}", LogLevel.Info, ZipFileName); DeleteFileButton.IsEnabled = true; } catch (Exception ex) { Logging.Editor("FTP download failed of {0}", LogLevel.Info, ZipFileName); Logging.Editor(ex.ToString()); } finally { CancelButton.IsEnabled = false; OpenFileButton.IsEnabled = true; OpenFodlerButton.IsEnabled = true; } break; } } StartTimerForClose(); }
/// <summary> /// 저널파일 FTP 전송 /// </summary> /// <returns></returns> private bool SetFTP() { bool bReturn = false; string strFtpMsg = string.Empty; SetMsgBar(osiMsgBar04, OpenItemStatus.None, strMsg16); try { string strServer = ConfigData.Current.AppConfig.PosFTP.FtpSvrIP1; string strUser = ConfigData.Current.AppConfig.PosFTP.User; string strPass = ConfigData.Current.AppConfig.PosFTP.Pass; string strPort = ConfigData.Current.AppConfig.PosFTP.FtpComPort1; string strPath = Path.Combine( FXConsts.JOURNAL.GetFolder(), string.Format("{0}-{1}-{2}.jrn", ConfigData.Current.AppConfig.PosInfo.SaleDate, ConfigData.Current.AppConfig.PosInfo.StoreNo, ConfigData.Current.AppConfig.PosInfo.PosNo) ); FileInfo fi = new FileInfo(strPath); if (fi.Exists) { if (strServer.Length > 0 && strUser.Length > 0 && strPass.Length > 0 && strPort.Length > 0 && strPath.Length > 0) { FtpUtils ftp = new FtpUtils(strServer, strUser, strPass, 10, TypeHelper.ToInt32(strPort)); if (ftp.Login(out strFtpMsg)) { //폴더 검사 string[] arrDir = ftp.GetFileList(string.Format("{0}", ConfigData.Current.AppConfig.PosFTP.JournalPath), out bReturn, out strFtpMsg); if (bReturn) { if (arrDir.Length > 0) { string strDir = string.Format("{0}/{1}", ConfigData.Current.AppConfig.PosFTP.JournalPath, ConfigData.Current.AppConfig.PosInfo.SaleDate); bool bMake = false; foreach (string strTemp in arrDir) { if (strTemp == strDir) { bMake = true; break; } } if (bMake) { //폴더존재시 이동 bReturn = ftp.ChangeDir(strDir, out strFtpMsg); } else { bReturn = ftp.MakeDir(strDir, out strFtpMsg); } } } } if (bReturn) { for (int i = 0; i < 3; i++) { if (ftp.Upload(strPath, out strFtpMsg)) { ftp.Close(); bReturn = true; break; } } } } } else { bReturn = true; } if (!bReturn) { string[] strBtnNm = new string[1]; strBtnNm[0] = WSWD.WmallPos.FX.Shared.ConfigData.Current.SysMessage.GetMessage("00045"); //strBtnNm[1] = WSWD.WmallPos.FX.Shared.ConfigData.Current.SysMessage.GetMessage("00190"); //LogUtils.Instance.LogException(strFtpMsg); //if (ShowMessageBox(MessageDialogType.Warning, null, strMsg22, strBtnNm) == DialogResult.Yes) //{ //} ShowMessageBox(MessageDialogType.Warning, null, strMsg22, strBtnNm); #if DEBUG m_ftpFailedCount++; if (m_ftpFailedCount >= MAX_FTP_COUNT) { bReturn = true; } else { bReturn = SetFTP(); } #else bReturn = SetFTP(); #endif //else //{ // bReturn = false; // //ChildManager.ShowProgress(false); // //SetControlDisable(false); // ////화면 종료 // //this.DialogResult = DialogResult.Cancel; // //if (!_bAuto) // //{ // // //시스템 종료 // // InitiateSystemShutdown("\\\\127.0.0.1", null, 0, false, false); // //} //} } } catch (Exception ex) { LogUtils.Instance.LogException(ex); } finally { SetMsgBar(osiMsgBar04, bReturn ? OpenItemStatus.OK : OpenItemStatus.Error, bReturn ? strMsg17 : strMsg18); } return(bReturn); }
static void Main(string[] args) { Utility.LogMessage("START"); FtpUtils.Download(); Utility.LogMessage("END"); }
/// <summary> /// 저널파일 FTP 전송 /// </summary> /// <returns></returns> private bool SetFTP() { bool bReturn = false; string strFtpMsg = string.Empty; try { string strServer = ConfigData.Current.AppConfig.PosFTP.FtpSvrIP1; string strUser = ConfigData.Current.AppConfig.PosFTP.User; string strPass = ConfigData.Current.AppConfig.PosFTP.Pass; string strPort = ConfigData.Current.AppConfig.PosFTP.FtpComPort1; string strPath = Path.Combine( FXConsts.JOURNAL.GetFolder(), string.Format("{0}-{1}-{2}.jrn", ConfigData.Current.AppConfig.PosInfo.SaleDate, ConfigData.Current.AppConfig.PosInfo.StoreNo, ConfigData.Current.AppConfig.PosInfo.PosNo) ); FileInfo fi = new FileInfo(strPath); if (strServer.Length > 0 && strUser.Length > 0 && strPass.Length > 0 && strPort.Length > 0 && strPath.Length > 0 && fi.Exists) { FtpUtils ftp = new FtpUtils(strServer, strUser, strPass, 10, TypeHelper.ToInt32(strPort)); if (ftp.Login(out strFtpMsg)) { //폴더 검사 string[] arrDir = ftp.GetFileList("/", out bReturn, out strFtpMsg); if (bReturn) { if (arrDir.Length > 0) { string strDir = string.Format("{0}-{1}-{2}", ConfigData.Current.AppConfig.PosInfo.SaleDate, ConfigData.Current.AppConfig.PosInfo.StoreNo, ConfigData.Current.AppConfig.PosInfo.PosNo); bool bMake = false; foreach (string strTemp in arrDir) { if (strTemp == @"/" + strDir) { bMake = true; break; } } if (bMake) { //폴더존재시 이동 bReturn = ftp.ChangeDir(strDir, out strFtpMsg); } else { bReturn = ftp.MakeDir(strDir, out strFtpMsg); } } } } if (bReturn) { for (int i = 0; i < 3; i++) { if (ftp.Upload(strPath, out strFtpMsg)) { ftp.Close(); bReturn = true; break; } } } } if (!bReturn) { string[] strBtnNm = new string[2]; strBtnNm[0] = "재시도"; strBtnNm[1] = "닫기"; LogUtils.Instance.LogException(strFtpMsg); if (ShowMessageBox(MessageDialogType.Question, null, "재시도", strBtnNm) == DialogResult.Yes) { bReturn = SetFTP(); } else { //화면 종료 this.DialogResult = DialogResult.Cancel; } } } catch (Exception ex) { } finally { } return(bReturn); }