Avatar of CPSRI
CPSRI
Flag 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
ASP.NETTCP/IP

Avatar of undefined
Last Comment
CPSRI

8/22/2022 - Mon
sanjithml

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.
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.
sanjithml

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...
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Star Gazr1

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.
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.
sanjithml

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);
}
}
}
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CPSRI

ASKER
could you help me to view and select the contents in ftp through asp.net page and select that files to download.
sanjithml

To get a directory listing of the FTP server's /pub directory:

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

ASKER
'Ftp.GetDirectoryDetail' this link not working
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
sanjithml

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)
sanjithml

or you can use ListDirectoryDetails
AlexPace

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.

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
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
sanjithml

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
CPSRI

ASKER
Thanks Sanjithml. from that link i learnd more things.