aspkiddy

aspkiddy

  • NA
  • 17
  • 0

Another method safer than StreamWriter and how can I save the file on another server (asp.net c sharp)

Oct 15 2009 10:15 AM
I have a form: when the user fills a form, the application takes this information and creates a data file (.csv) and put it (data file) on the server in a directory (name of this directory is [information]) where the web site is located.

 using (System.IO.StreamWriter SW = new System.IO.StreamWriter(Server.MapPath("save/information/Data_" + strDate + ".csv")))

{
SW.WriteLine(s.FirstName + ";" + s.LastName + ";" + s.Address1 + ";");
SW.Close();
}
After, I changed the path for save the file, in a different server than the Web server

 StreamWriter SW = new StreamWriter(@"\\111.222.1.00\c$\Inetpub\wwwroot\site_toto\ save\information\Data_" + strDate + ".csv");


It must disable the firewall on server so that it works. I can't it.

So instead of filing the file with system Windows, I'd like to put with FTP protocole on another place, but I do not know how I can do.

I have a class!(by J.P. Trosclair)  How can I integrate it?

Is that correct if I do like that ? :


 using (FTP ftplib = new FTP(MapPath ("Data_" + strDate + ".csv")));

try
{
ftplib.Connect("ftp.toto.com",
"tata",
"pata");
ftplib.ChangeDir("information/");
}
catch(Exception ex)
{
Console.WriteLine(s.FirstName + ";" + s.LastName + ";" + s.Address1 + ";");
}

try
{
int perc = 0;


ftplib.OpenDownload("Data_" + strDate + ".csv", true);
while(ftplib.DoDownload() > 0)
{
perc = (int)((ftplib.BytesTotal * 100) / ftplib.FileSize);
Console.Write("\rDownloading: {0}/{1} {2}%",
ftplib.BytesTotal, ftplib.FileSize, perc);
Console.Out.Flush();
}
Console.WriteLine("");
}
catch(Exception ex)
{
Console.WriteLine("");
Console.WriteLine(ex.Message);
}


What do you think of my integration code that you see above? is that this can work or I'm completely wrong



the beginning of the code should I add [using ftplib]

[(using System;)after :]

 using ftplib;



Answers (1)