Monday, September 29, 2008

Download FTP File by C#

Dear All,

How are you? Hope you all are doing well.
I got a easy way to download file from FTP and search file from FTp, Upload file to FTP.
I mean u can do anything in your FTP Task in this way..


Step:1 : Write Control File , Say name is "temp.txt"


private void writeControlFile(string strFileName)
{
StreamWriter SW = new StreamWriter("temp.txt");
string strFileOriginalName = "temp";//download file
string TextContent = "username" + Environment.NewLine + "password" + Environment.NewLine + "ascii" + Environment.NewLine + "cd /usr/gsm/ne_data/ev_logs";
TextContent = TextContent + Environment.NewLine + "mget " + strFileOriginalName;
TextContent = TextContent + Environment.NewLine + "y" + Environment.NewLine + "quit";
SW.WriteLine(TextContent);
SW.Close();
}

step 2: write script file

test.bat file contains

ftp.exe -s:temp.txt ftpip

Private void RunScript()
{
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(@"test.bat");System.Diagnostics.Process obj = System.Diagnostics.Process.Start(info);
}