Link to home
Start Free TrialLog in
Avatar of CPSRI
CPSRIFlag for United States of America

asked on

Connecting to FTP

Hi,
   I want to connect to my FTP server through ASP,is it possible to connect?if possible please let me know the solution for this,because i have tried in many ways to connect.But it was not connected.Please let me the solution or any releted URLs for this.

 Thank you
Avatar of sanjithml
sanjithml
Flag of India image

You have mentioned here that you are not able to connect. but you didn't mention it what problem you are facing when you try to connect.
let me know.
Avatar of CPSRI

ASKER

Hi sanjithml,
    Actually i don't  know how to connect. But i Tried like 'SQLConnection String' but it not working. Could you Help Me  how to Connect and how many ways to connect through ASP.NET Page.
can u ftp manually to a site from command line?
does your ftp site need authentication?

try ftp ftp.sunfreeware.com from command line

let me know the problem you face...
What version of .NET are you using?
Here is an article on how to upload a file via FTP in .NET Framework v2.0
http://www.devasp.net/net/articles/display/280.html
using FTPWebRequest and FTPWebResponse classes.
There may be more enhanced FTP functions in later versions of .NET Framework, but I am not sure of the specifics that you need to do.
Avatar of CPSRI

ASKER

Ya my ftp server need authentication.. i want to give ftp name, user name and password through asp.net to access all the content in that server.
this example is helpful for uploading file to ftp site. Get your stuff from here.

//C# Equivalent
using System.IO;
using System.Net;

namespace ftpupload
{
public class ftpupload
{

public void uploadFileUsingFTP(string CompleteFTPPath, string CompleteLocalPath, string UName, string PWD)
{
//Create a FTP Request Object and Specfiy a Complete Path
FtpWebRequest reqObj = (FtpWebRequest)WebRequest.Create(CompleteFTPPath);
//Call A FileUpload Method of FTP Request Object
reqObj.Method = WebRequestMethods.Ftp.UploadFile;
//If you want to access Resourse Protected You need to give User Name and PWD
reqObj.Credentials = new NetworkCredential(UName, PWD);
//FileStream object read file from Local Drive
FileStream streamObj = File.OpenRead(CompleteLocalPath);
//Store File in Buffer
byte[] buffer = new byte[streamObj.Length + 1];
//Read File from Buffer
streamObj.Read(buffer, 0, buffer.Length);
//Close FileStream Object Set its Value to nothing
streamObj.Close();
//Upload File to ftp://localHost/ set its object to nothing
reqObj.GetRequestStream().Write(buffer, 0, buffer.Length);
}
}
}
Avatar of CPSRI

ASKER

could you help me to view and select the contents in ftp through asp.net page and select that files to download.
To get a directory listing of the FTP server's /pub directory:

Dim fullList As FtpDirectory = myFtp.GetDirectoryDetail("/pub/")
Avatar of CPSRI

ASKER

'Ftp.GetDirectoryDetail' this link not working
bcos you have to create an instance...

 create a new instance of the object, defining the host, username and password.

Dim myFtp As New FtpClient(hostname, username, password)
or you can use ListDirectoryDetails
I have another idea if you don't want your ASP page to delay rendering while doing the FTP transaction...  

Assuming you have permission to install software on your web server, you could install a Robo-FTP "hot send" service that watches a local folder for new files and then sends anything it finds to the remote FTP site.  This way, all your ASP has to do is put the uploaded file into the outgoing folder.  If you wanted to get fancy about it, you could configure the Robo-FTP command script to only send files of a certain size, type, filename etc.  If users log in to your web app you could put the uploaded file in a subfolder with the same name as the user and then set the service up to apply different filtering rules to files uploaded by different users.

Avatar of CPSRI

ASKER

No, i have not permission to install software or Download the software. But i have permission to access the webserver and that details. could you help me this site"ftp.sunfreeware.com " code in C#. i want to know and understand that code.  how is it works and functionality. I am Very new to FTP .
ASKER CERTIFIED SOLUTION
Avatar of sanjithml
sanjithml
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CPSRI

ASKER

Thanks Sanjithml. from that link i learnd more things.