Discuss (FTP), (FTP on .NET CF) and (FTPS, SFTP and SCP).
no avatar
User

developer_75

Posts

2

Joined

Wed Jun 01, 2005 1:04 pm

GET function can't work for large file download

by developer_75 » Wed Jun 01, 2005 1:14 pm

Hi,

Need some help.

I try to run my program to download file via the Get function but it is only work for file that is a few KB,downloading anything file larger will generate the System.IO...."The process cannot accces the (local drive\local directory\filename)" error.
Can anyone give me some advice?
Thanks.
I have attached my code below:

using System;
using System.IO;
using EnterpriseDT.Net.Ftp;
using EnterpriseDT.Util.Debug;

namespace DHFTP
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class MyFTP
{
/// <summary>
/// The main entry point for the application.
/// </summary>
///
private FTPClient clsFTP;
private string strHost;
private string strUserID;
private string strUserPW;
private string startFolder;
private string strTextFilePath;
private string strPathToSave;

[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
// we want remote host, user name and password
if (args.Length < 6)
{
Usage();
System.Environment.Exit(1);
}
MyFTP clsMyFTP = new MyFTP(args[0],args[1],args[2],args[3],args[4],args[5]);
clsMyFTP.StartFTP();
}
public static void Usage()
{
System.Console.Out.WriteLine("Usage: DHFTP remotehost user password FTPstartFolder textFilePath downloadPath");
}
public MyFTP()
{}
public MyFTP(string host,string userID,string password,string stFolder,string textFilePath,string downloadPath)
{
strHost = host;
strUserID = userID;
strUserPW = password;
startFolder = stFolder;
strTextFilePath = textFilePath;
strPathToSave = downloadPath;
}

public void StartFTP()
{
try
{
Login();
string[] strHDD;
strHDD = clsFTP.Dir(startFolder,true);
//loop thru the list of HDD
for(int i=0;i<strHDD.Length;i++)
{
string delimStr = " ";
char [] delimiter = delimStr.ToCharArray();
string[] strLine = strHDD[i].Split(delimiter);
string strHDDFolder = strLine[strLine.Length-1].ToString();
//Console.WriteLine(strHDDFolder);

if (strHDDFolder != "." && strHDDFolder != "..")
{
//check if HDD is processed already
if (strHDDFolder.Length < 9 || strHDDFolder.Substring(0,9) != "Processed" )
{
//get the list of album of the HDD
string[] strAlbumFolder = clsFTP.Dir(startFolder + "\\" + strHDDFolder,true);
//loop thru the list of album
for(int j=0;j<strAlbumFolder.Length;j++)
{
string[] arrAlbumFolder = strAlbumFolder[j].Split(delimiter);
string strAlbum = arrAlbumFolder[arrAlbumFolder.Length-1].ToString();
//Console.WriteLine(strAlbum);
if(strAlbum != "." && strAlbum != ".." && strAlbum.Length > 4)
{
if(strAlbum.Substring(strAlbum.Length-3,3)!= "txt")
{
//get the content details of the folder
string[] arrContent = clsFTP.Dir(startFolder + "\\" + strHDDFolder + "\\" + strAlbum,true);
//loop thru list of content
for(int k=0;k<arrContent.Length;k++)
{
string[] arrFile = arrContent[k].Split(delimiter);
string strFile = arrFile[arrFile.Length-1].ToString();
//check if it's a valid file
if (strFile != "." && strFile != "..")
{
if(strFile.Substring(strFile.Length-4,1)=="." || strFile.Substring(strFile.Length-5,1)==".")
{
Login();
clsFTP.Get(strPathToSave + "\\" + strFile,startFolder + "\\" + strHDDFolder + "\\" + strAlbum + "\\" + strFile);
Console.WriteLine("Downloaded: " + startFolder + "\\" + strHDDFolder + "\\" + strAlbum + "\\" + strFile);
WriteToFile(startFolder + "\\" + strHDDFolder + "\\" + strAlbum + "\\" + strFile);
}
}
}
}
}
}
//rename the processed folder
Login();
clsFTP.Rename(startFolder + "\\" + strHDDFolder ,startFolder + "\\Processed_" + strHDDFolder);
}
}
}
//Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
}
private void Login()
{
clsFTP = new FTPClient(strHost);
clsFTP.Timeout = 1000000;
clsFTP.Login(strUserID,strUserPW);
clsFTP.ConnectMode = FTPConnectMode.ACTIVE;
clsFTP.TransferType= FTPTransferType.ASCII;
}
private void WriteToFile(string text)
{

string strTextToFile;
strTextToFile = text + "|" + TodayInYYYYMMDD();
StreamWriter sw = new StreamWriter(strTextFilePath,true);
sw.WriteLine(strTextToFile);
sw.Close();
}
private string TodayInYYYYMMDD()
{
DateTime dt = DateTime.Now ;
string strYear = dt.Year.ToString();
string strMth = dt.Month.ToString();
string strDay = dt.Day.ToString();
if (strMth.Length < 2)
{
strMth = "0" + strMth;
}
if (strDay.Length < 2)
{
strDay = "0" + strDay;
}
return strYear + strMth + strDay;
}
}
}
no avatar
User

developer_75

Posts

2

Joined

Wed Jun 01, 2005 1:04 pm

Problem Solved

by developer_75 » Fri Jun 03, 2005 12:30 pm


Who is online

Users browsing this forum: No registered users and 130 guests

Powered by phpBB ® | phpBB3 Style by KomiDesign