public void UploadToFtp() { System.Console.WriteLine("Starting uploads..."); string username = "******"; string directory = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "/"; string passwordLocationFile = directory + "pw.txt"; // chop off "file:" passwordLocationFile = passwordLocationFile.Substring(5); //string password = "******"; string password = System.IO.File.ReadAllText(passwordLocationFile); bool succeeded = false; string errorString = null; try { FtpManager.UploadFile(mZippedTemplateFile, mRemoteZipLocation, username, password, false); System.Console.WriteLine("Uploaded to " + mRemoteZipLocation); foreach (string file in mDlls) { string sourceFile = mBuildDirectory + file; string destinationFile = FileManager.MakeRelative(file, mTemplateLocation); string remoteFileLocation = mSingleDllLocation + FileManager.RemoveDirectory(file); FtpManager.UploadFile(sourceFile, remoteFileLocation, username, password, false); System.Console.WriteLine("Uploaded to " + remoteFileLocation); } succeeded = true; } catch (Exception exception) { errorString = exception.ToString(); } if (succeeded) { System.Console.WriteLine("Uploads succeeded"); } else { System.Console.WriteLine("Uploads failed"); System.Console.Write(errorString); } }
public static string GetDirectory(string fileName, RelativeType relativeType) { int lastIndex = System.Math.Max( fileName.LastIndexOf('/'), fileName.LastIndexOf('\\')); if (lastIndex == fileName.Length - 1) { // If this happens then fileName is actually a directory. // So we should return the parent directory of the argument. lastIndex = System.Math.Max( fileName.LastIndexOf('/', fileName.Length - 2), fileName.LastIndexOf('\\', fileName.Length - 2)); } if (lastIndex != -1) { bool isFtp = false; #if !XBOX360 && !SILVERLIGHT && !WINDOWS_PHONE && !MONOGAME isFtp = FtpManager.IsFtp(fileName); #endif if (FileManager.IsUrl(fileName) || isFtp) { // don't standardize URLs - they're case sensitive!!! return(fileName.Substring(0, lastIndex + 1)); } else { if (relativeType == RelativeType.Absolute) { return(FileManager.Standardize(fileName.Substring(0, lastIndex + 1), null)); } else { return(FileManager.Standardize(fileName.Substring(0, lastIndex + 1), "")); } } } else { return(""); // there was no directory found. } }