/// <summary> /// method to upload the contents of a file from a remote URI /// </summary> /// <param name="ftpUri"></param> /// <param name="user"></param> /// <param name="pass"></param> /// <returns></returns> public void PostFileToSite(string fileName) { try { using (FtpLib.FtpConnection ftp = new FtpLib.FtpConnection(_ftpSite.Site, _ftpSite.Username, _ftpSite.Password)) { try { ftp.Open(); /* Open the FTP connection */ ftp.Login(); /* Login using previously provided credentials */ //ftp.SetCurrentDirectory(m_FTPServerDirectory); /* change current directory */ ftp.PutFile(fileName); } catch (FtpLib.FtpException e) { LogIt("FtpMgr::PostFileToSite():FtpExceptionCaught: " + e.Message); LogIt(e.StackTrace); } } } catch (FtpLib.FtpException e) { LogIt("FtpMgr::PostFileToSite():FtpExceptionCaught: " + e.Message); LogIt(e.StackTrace); } }
/// <summary> /// method to upload the contents of a file from a remote URI /// </summary> /// <param name="ftpUri"></param> /// <param name="user"></param> /// <param name="pass"></param> /// <returns></returns> public void PostFileToSite(string fileName) { try { using (FtpLib.FtpConnection ftp = new FtpLib.FtpConnection(_ftpSite.Site, _ftpSite.Username, _ftpSite.Password)) { try { ftp.Open(); /* Open the FTP connection */ ftp.Login(); /* Login using previously provided credentials */ //ftp.SetCurrentDirectory(m_FTPServerDirectory); /* change current directory */ ftp.PutFile(fileName); } catch (FtpLib.FtpException e) { LogIt("FtpMgr::PostFileToSite():FtpExceptionCaught: " + e.Message); LogIt(e.StackTrace); } } } catch (FtpLib.FtpException e) { LogIt("FtpMgr::PostFileToSite():FtpExceptionCaught: " + e.Message); LogIt(e.StackTrace); } }
/// <summary> /// Urca o imagine pe contul FTP. /// </summary> /// <param name="imgPath">Calea catre poza de le computer.</param> /// <param name="newName">Numele imaginii de pe server.</param> /// <returns>True, daca s-a urcat cu succes si False daca au aparut erori.</returns> public static bool UploadImage(string imgPath, string newName) { try { FtpConnection conn = new FtpConnection(Globals.FTP_SERVER, 21, Globals.FTP_USER, Globals.FTP_PASSWORD); conn.Open(); conn.Login(); conn.SetCurrentDirectory("/public_html/CompanyWorkManagement/"); conn.PutFile(imgPath, newName + ".jpg"); return true; } catch { return false; } }
/// <param name="imgPath">Calea catre poza de le computer.</param> /// <param name="newName">Numele imaginii de pe server.</param> public static bool UploadImage(string imgPath, string newName) { try { FtpConnection conn = new FtpConnection(ftpServer, 21, ftpUser, ftpPassword); conn.Open(); conn.Login(); conn.SetCurrentDirectory("/ion"); conn.PutFile(imgPath, newName + ".jpg"); return true; } catch { return false; } }
public FileFilter CopyToFtp(string sourceDirectory, FtpDirectory ftpDir) { using (FtpConnection ftpConnection = new FtpConnection(ftpDir.Host, ftpDir.Port, ftpDir.Username, ftpDir.Password)) { ftpConnection.Open(); ftpConnection.Login(); foreach (WrappedFileSystemInfo fileSystemInfo in GetFilesAndFolders(sourceDirectory)) { if (fileSystemInfo is WrappedDirectoryInfo) { var combinedPath = Path.Combine(ftpDir.BaseDirectory, fileSystemInfo.PathWithoutBaseDirectory); if (!ftpConnection.DirectoryExists(combinedPath)) ftpConnection.CreateDirectory(combinedPath); } else { if (!ftpConnection.DirectoryExists(ftpDir.BaseDirectory)) { ftpConnection.CreateDirectory(ftpDir.BaseDirectory); } var combinedPath = Path.Combine(ftpDir.BaseDirectory, fileSystemInfo.PathWithoutBaseDirectory); var newPath = Path.GetDirectoryName(combinedPath); if (!ftpConnection.DirectoryExists(newPath)) { ftpConnection.CreateDirectory(newPath); } ftpConnection.SetCurrentDirectory(newPath); ftpConnection.PutFile(fileSystemInfo.FullName); } } } return this; }
private string CopyComparisonScript(string refHost, string refEnv) { string remoteScriptName = string.Empty; FtpConnection connection = new FtpConnection(refHost, "mxftp", "mxftp"); string localFileName = Path.GetTempFileName(); CommonUtils.WriteFile(localFileName, ComparisonScript); try { try { connection.Open(); //bgDoServerWork.ReportProgress(5, "Validating Results..."); } catch (Exception ex) { CommonUtils.ShowError(ex.Message, ex); } connection.Login(); connection.SetCurrentDirectory(refEnv); //Path.GetTempFileName remoteScriptName = Path.GetFileName(localFileName); connection.PutFile(localFileName); connection.RenameFile(remoteScriptName, Path.GetFileNameWithoutExtension(remoteScriptName) + ".sh"); //connection.SendCommand("chmod 777 " + Path.GetFileNameWithoutExtension(remoteScriptName) + ".sh"); remoteScriptName = Path.GetFileNameWithoutExtension(remoteScriptName) + ".sh"; } finally { connection.Close(); connection.Dispose(); } return remoteScriptName; }
protected void NewFoodPopupOk(object sender, EventArgs e) { if (DataValidate()) { bool checkFtpNotError = true; int foodId = 0; if (Session["edit"] != null && (int)Session["edit"] == 1) { foodId = (int) Session["id"]; } else { foodId = FoodController.GetMaxId(); } String imageFileName = ""; if (NewFoodImage.PostedFile != null) { var postImage = NewFoodImage.PostedFile; int imageFileLenght = postImage.ContentLength; string imageExtension = Path.GetExtension(postImage.FileName); imageFileName = foodId + imageExtension; if (imageFileLenght > 0 && (imageExtension == ".png" || imageExtension == ".jpg" || imageExtension == ".gif")) { byte[] myData = new byte[imageFileLenght]; // Read uploaded file from the Stream postImage.InputStream.Read(myData, 0, imageFileLenght); // Create a name for the file to store string strFilename = Path.GetFileName(postImage.FileName); String absServerFileName = Server.MapPath("~/Upload/" + strFilename); // Write data into a file if (FileOperation.WriteToFile(absServerFileName, ref myData)) { using (var ftpConnection = new FtpConnection("localhost",21,"imageupload","123456789")) { ftpConnection.Open(); ftpConnection.Login(); ftpConnection.SetCurrentDirectory("/"); try { ftpConnection.PutFile(absServerFileName, imageFileName); } catch (Exception) { //Báo lỗi checkFtpNotError = false; throw; } finally { ftpConnection.Close(); } } } } } String foodName = NewFoodName.Text; int foodPrice = int.Parse(NewFoodPrice.Text); int foodType = int.Parse(NewFoodType.SelectedValue); String imageOnCdn = imageFileName; String foodDetail = CKEditorNewFood.Text; if (Session["edit"] != null) { foodId = int.Parse(Session["id"].ToString()); if (NewFoodImage.PostedFile == null) { imageOnCdn = null; } if (!FoodController.Update(foodId, foodName, foodPrice, foodType, imageOnCdn, foodDetail)) { OfficeMessageBoxUpdateFoodFail.Show(); OfficePopupNewFood.Hide(); } else { OfficeMessageBoxUpdateFoodSuccess.Show(); OfficePopupNewFood.Hide(); } Session["edit"] = null; } else { if (checkFtpNotError) { if (!FoodController.Insert(foodId, foodName, foodPrice, foodType, imageOnCdn, foodDetail)) { OfficeMessageBoxAddFoodFail.Show(); OfficePopupNewFood.Hide(); } else { OfficeMessageBoxAddFoodSuccess.Show(); OfficePopupNewFood.Hide(); } } } } }
private void SendFileToServer(string filename) { List<string> remoteFiles = new List<string>(); string localDownloadDirectory = string.Empty; FtpConnection connection = new FtpConnection("dell014srv", "mxftp", "mxftp"); try { try { connection.Open(); } catch (Exception ex) { CommonUtils.ShowError(ex.Message, ex); } connection.Login(); connection.SetCurrentDirectory("/dell014srv1/automation/automation-Jobs/"); connection.PutFile(filename, "launchJob.sh"); } finally { connection.SetLocalDirectory(Path.GetTempPath()); connection.Close(); connection.Dispose(); } }