on 04-01-2015 9:52 AM
Hello Friends,
My task is to upload a CSV file into a specified FTP loacation.But the system is throwing time out message from a line of the code. Please help me out on this issue.
public static string UploadFile(string ftpUrl, string userName, string password, string uploadFTPDirectory, string localFilePath)
{
string PureFileName = new FileInfo(localFilePath).Name;
String uploadUrl = String.Format("{0}{1}/{2}", ftpUrl, uploadFTPDirectory, PureFileName);
//String uploadUrl = String.Format("{0}{1}", ftpUrl, uploadFTPDirectory);
FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(uploadUrl);
ftpRequest.Proxy =null;
ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
ftpRequest.Credentials = new NetworkCredential(userName, password);
ftpRequest.UseBinary = true;
ftpRequest.UsePassive = false;
try
{
byte[] fileData = File.ReadAllBytes(localFilePath);
ftpRequest.ContentLength = fileData.Length;
using (Stream fileStream = ftpRequest.GetRequestStream())
{
fileStream.Write(fileData, 0, fileData.Length);
fileStream.Close();
}
using (FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse())----------'Sytem throws the Timed out Message here.'
{
return ftpResponse.StatusDescription;
}
}
catch(WebException e)
{
string s = ((FtpWebResponse)e.Response).StatusDescription;
return s;
}
}
With thanks and Regards,
Rajeev M Kartha
I dont know why you posted this here. but you might want to disable firewall.
FTP does require two ports to work 20, and 21.
Frank
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
110 | |
12 | |
11 | |
6 | |
5 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.