Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | Hi ,
I want to fetch FTP directory listing using store procedure of sql server 2000.
like in FTP i hvae created folder like
Test1
Test2 ---> Test3 (this is sun directory of Test2)
[b]
I want the Output list of directory listing
ftp://server/test1
ftp://server/test2
ftp://server/test2/test3[/b] | |
| | | |
| Re:Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | Hi
I think we need know about your table structure to write SP. And for the easy you keep the folders root level column also then it would be easy to generate the following output.
Anyhow can you post your table here.
Thank you | |
| | | |
| Re:Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | Hi ,
actually i want to fetch FTP detail from the server .
I have created the code in .net but its execution speed is low .
so , I want to do this in sql server .
in .net I have created code like this :
public string[] GetFileList(string path)
{
string[] downloadFiles;
StringBuilder result = new StringBuilder();
FtpWebRequest reqFTP;
string[] result1 = null;
try
{
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(
path));
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(ftpUserID,
ftpPassword);
reqFTP.Method = WebRequestMethods.Ftp.ListDirectory;
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
StreamReader reader = new StreamReader(response
.GetResponseStream(), System.Text.Encoding.UTF8);
result1 = (reader.ReadToEnd().Split('\n'));
//string line = reader.ReadLine();
//while (line != null)
//{
// if (line.Contains("DIR") == true)
// {
// result.Append(line);
// result.Append("\n");
// line = reader.ReadLine();
// }
//}
// result.Remove(result.ToString().LastIndexOf("\n"), 1);
reader.Close();
response.Close();
return result1;
// to remove the trailing '\n'
//result.Remove(result.ToString().LastIndexOf('\n'), 1);
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message);
downloadFiles = null;
return downloadFiles;
}
} | |
| | | |
| Re:Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | Hi
Check you code , you can improve your code like this way.
[color=#0000FF]//Connects to the FTP server and request the list of available files
public List GetFileList(string FTPAddress, string username, string password)
{
List files = new List();
try
{
//Create FTP request
FtpWebRequest request = FtpWebRequest.Create(FTPAddress) as FtpWebRequest;
request.Method = WebRequestMethods.Ftp.ListDirectory;
request.Credentials = new NetworkCredential(username, password);
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = false;
using (FtpWebResponse response = request.GetResponse() as FtpWebResponse)
{
using (Stream responseStream = response.GetResponseStream())
{
using (StreamReader reader = new StreamReader(responseStream))
{
while (!reader.EndOfStream)
{
files.Add(reader.ReadLine());
}
}
}
}
}
catch (Exception ex)
{
// write to log
}
return files;
}[/color]
Now try and let me know
thank you | |
| | | |
| Re:Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | [color=#800080]Hi ,
thanx for the code .
I have send you my whole code ....
in which i get directory and also get subdirectory .
please check it .
in the DirectoriesList object i got all the detail of FTP folder list .
but in my FTP there are 100 folders and all folder contains sub folder .
so , to get all the details from the FTP the execution time is so slow .
so , please give me any idea to improve the speed of execution .[/color]
[color=#008000]
[b]void TogetFolderinfo()
{
for (int directoryCount = 0; directoryCount < DirectoriesList.Count; directoryCount++)
{
currentDirectory = DirectoriesList[directoryCount].ToString() + "/";
if (currentDirectory.StartsWith("ftp://", StringComparison.OrdinalIgnoreCase) == false)
{
currentDirectory = string.Concat("ftp://" + ftpServerIP, currentDirectory);
}
string[] directoryInfo = GetFileList(currentDirectory);
if (directoryInfo != null)
{
for (int counter = 0; counter < directoryInfo.Length; counter++)
{
string currentFileOrDir = directoryInfo[counter];
if (currentFileOrDir.Length < 1)
// If all entries were scanned then break
{ break; }
currentFileOrDir = currentFileOrDir.Replace("\r", "");
GetFtpFileInfo(currentFileOrDir, currentDirectory);
if (FileType == DirectoryEntryType.Directory)
{
DirectoriesList.Add(Path + FullName); //If Directory add to the collection.
}
}
}
}[/b][/color] | |
| | | |
| Re:Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | Hi
I try to fix your code it's say following are missing
1.DirectoriesList
2.GetFileList
3.GetFtpFileInfo
So please check and me full code or send to info@codegain.com
thank you | |
| | | |
| Re:Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | k .. i will send you full code ... | |
| | | |
| Re:Fetch FTP File listing using store procedure | 23 Feb 2010 01:02:51 |
| | Hi
I check your code it's should take time man, because of you are querying in recursive mode, i'm try yo modify your and will send you ASAP.
At same time i will open new thread here to with your code make it faster.
Thank you. | |
| | | |
|