Click here to Skip to main content
15,885,365 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello every one im trying to download all files from ftp server to local folder in my server total 19k files are there but i downloaded only 4k files after that my connection was timed out how can i download the rest all files from ftp server...pls give me solution



THANK YOU....
Posted
Updated 4-Aug-12 2:56am
v2
Comments
kk2014 4-Aug-12 5:22am    
what is your session timeout? if it is less than please increase it,,,,
abhilash yelmelwar 6-Aug-12 1:32am    
im not using any sessions here...
Dave Kreskowiak 4-Aug-12 11:07am    
If you're getting a timeout, you're doing something very very wrong. Without seeing your FTP download code it's pretty much impossible to tell you what you're doing wrong.
abhilash yelmelwar 6-Aug-12 1:31am    
hello dave....this is my code..i tihnk we can download rest files using time and date but im not able download files...




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace Support
{
public partial class FTP : Form
{

public FTP()
{
InitializeComponent();

}

string filetime = @"E:\FTP photos.txt";
private void Download(string line)
{
FtpWebRequest reqFTP;
try
{

string filepath = @"E:\FTP photos";

//F:\Studentphotos
FileStream outputStream = new FileStream(filepath + "\\" + line, FileMode.Create);

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + txtip.Text + "/" + txtupload.Text + "/" + line));
//string str = System.IO.Directory.GetFiles(filepath).ToString();

//System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(filepath);

//if (File.Exists(filepath + "//" + line))

//string str = File.Exists(filepath).ToString();

System.IO.File.Exists(line);
File.Exists(line);


//if(line==str)

// {

if (File.Exists(filepath))
{
GetFileList();
}
else
{

reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(txtuser.Text, txtpass.Text);

FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();

long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];

readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
{
outputStream.Write(buffer, 0, readCount);
readCount = ftpStream.Read(buffer, 0, bufferSize);
}

ftpStream.Close();
outputStream.Close();
response.Close();
// MessageBox.Show("Download Completed");
}
}
//}

catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}

private void Download1(string filePath, string fileName)
{
FtpWebRequest reqFTP;
try
{
//filePath = <<The full path where the file is to be created.>>,
//fileName = <<Name of the file to be created(Need not be the name of the file on FTP server).>>
FileStream outputStream = new FileStream(filePath + "\\" + fileName, FileMode.Create);

reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + txtip.Text + "/" + txtupload.Text));
reqFTP.Method = WebRequestMethods.Ftp.DownloadFile;
reqFTP.UseBinary = true;
reqFTP.Credentials = new NetworkCredential(txtuser.Text,txtpass.Text);
FtpWebResponse response = (FtpWebResponse)reqFTP.GetResponse();
Stream ftpStream = response.GetResponseStream();
long cl = response.ContentLength;
int bufferSize = 2048;
int readCount;
byte[] buffer = new byte[bufferSize];

readCount = ftpStream.Read(buffer, 0, bufferSize);
while (readCount > 0)
Dave Kreskowiak 6-Aug-12 10:23am    
OK, this code is a pile of spaghetti. You've got a single method doing far more than it should and it really doesn't make any sense either. I can see why it only downloads a single file. But, that's not really the point here. Scrap this and start over.

Write a download method that does only one thing - download the file at the specified URL and write the data to a specified local file. It should NOT parse any text file or get any data from textboxes, ..., nothing. It should have a name like "DownloadFromFtpUrl" and take in two parameters: a URL to download from, and a filepath to write the data to. That's it, nothing more. Once you have that working, you can create a second version of this that adds credential parameters.

Once you have that written and working, then you can add other methods to parse a text file and build the URLs and filepaths for the above method to act on.

1 solution

This has nothing to do with ASP.NET as far as I can see. I don't even see any sign you're using C# for this, as opposed to an FTP program. It sounds like you have problems with your internet connection.
 
Share this answer
 
Comments
abhilash yelmelwar 6-Aug-12 1:33am    
no dude my connection was ok...but my downloading is stopped suddenly with out any message

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900