Hi Im doing project in ftp process automation..
i have to download files from ftp server for every day.. So i have to check the date of the uploaded files.. im doing project in c# .net using REBEX.. i need sample code for it..
so anybody can help me?
Loading
Lalit MPosted Jan 29, 2010, 1:59 AM
------------
public void DownloadFile(string ftppath, string destfile,string strFileName)
{
try
{
//create ftp object
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftppath);
//userid and password for the ftp server
ftp.Credentials = new NetworkCredential("ftp_username", "ftp_password");
//Set keepalive property true to multiple use of same instance
ftp.KeepAlive = true;
//use binary method to upload data
ftp.UseBinary = true;
//set action to check the date and time of ftp file
ftp.Method = WebRequestMethods.Ftp.GetDateTimestamp;
FtpWebResponse response = (FtpWebResponse)ftp.GetResponse();
//recieve ftp file date time
DateTime modification = response.LastModified;
// Download the data
string sBackupFileName = strFileName + modification.ToString("MM_dd_yyyy") + "_" + modification.Hour.ToString() + "_" + modification.Minute.ToString() + "_" + modification.Second.ToString() + ".xml";
//download file in byte , for this call another user defined method given in this post
byte[] Data = DownloadData(ftppath);
// Save the data to disk
FileStream fs = new FileStream(destfile + sBackupFileName, FileMode.Create);
fs.Write(Data, 0, Data.Length);
//close the file stream
fs.Close();
}
catch (Exception ex)
{
//exception handling
throw;
}
}
For Reference
More info
-----------
http://www.vcskicks.com/download-file-ftp.php
http://blogs.techrepublic.com.com/howdoi/?p=165
Jimmy OsmondPosted Jun 30, 2010, 5:12 PM
Lalit MPosted Jan 29, 2010, 2:31 AM
Hope this help you....