1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
private void SendWindSCP(Parametrage parametrage)
{
try
{
//création du fichier text de script
string pathFileScript = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "EXPORT_FTP.txt");
if (System.IO.File.Exists(pathFileScript)) { System.IO.File.Delete(pathFileScript); }
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(pathFileScript, false, Encoding.ASCII))
{
sw.WriteLine(@"open """ + parametrage.SessionWinSCP + "");
sw.WriteLine("option batch on");
sw.WriteLine("option confirm off");
sw.WriteLine("cd /");
sw.WriteLine(@"lcd """ + parametrage.PathDirDest + "");
sw.WriteLine("put " + parametrage.NameFile);
sw.WriteLine("exit");
sw.Flush();
sw.Close();
}
//transfere via WINSCP
Outils.Process.Execute(parametrage.PathWinSCP, @"/console /script=""" + pathFileScript + "");
//SUppression du fichier de script
if (System.IO.File.Exists(pathFileScript)) { System.IO.File.Delete(pathFileScript); }
}
catch (Exception ex)
{
throw new ApplicationException("Erreur lors de l'envoi par FTP, fichier :" + parametrage.PathWinSCP +
", session : " + parametrage.SessionWinSCP +
", Erreur : " + ex.Message);
}
}
public static void Execute(string fileName, string argument)
{
using (System.Diagnostics.Process proc = new System.Diagnostics.Process
{
StartInfo = new System.Diagnostics.ProcessStartInfo
{
FileName = @fileName,
Arguments = @argument,
UseShellExecute = true,
RedirectStandardOutput = false,
CreateNoWindow = true,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal
}
})
{
proc.Start();
proc.WaitForExit();
proc.Close();
proc.Dispose();
}
} |
Partager