Sign in to follow this  

[web] allowing my customers to upload files to my ftp server

This topic is 4268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

basically you need to download a cgi library developed in c#
and in that library, there are probably file uploading classes, where you can upload files through a form.

and using javascripts and such, you can go really far with those.

edit: oops. the above is if you want to upload it using the http.
and if you want to upload files via an ftp server
you need to install an ftp server software on your server computer
and your client must connect to your ftp server ( usually port 21 ) using an ftp client program.

Share this post


Link to post
Share on other sites
Quote:
Original post by Tradone

edit: oops. the above is if you want to upload it using the http.
and if you want to upload files via an ftp server
you need to install an ftp server software on your server computer
and your client must connect to your ftp server ( usually port 21 ) using an ftp client program.


thanks for replying i bought the domain name and the host from a company called NetworkSolutions and i bought the professional Windows package so how i can install an ftp server software on there server ?? what i want to do is letting other people upload files to my web space i bought, so what i can do in this case ???

Share this post


Link to post
Share on other sites
The FtpWebRequest class is new in .Net 2.0 framework. I once wrote an ftp-library for .net, but that isn't necessary anymore. Here's some sample code, for more detailed info look into MSDN.


using System;
using System.Net;
using System.Threading;

using System.IO;
namespace Examples.System.Net
{
public class FtpState
{
private ManualResetEvent wait;
private FtpWebRequest request;
private string fileName;
private Exception operationException = null;
string status;

public FtpState()
{
wait = new ManualResetEvent(false);
}

public ManualResetEvent OperationComplete
{
get {return wait;}
}

public FtpWebRequest Request
{
get {return request;}
set {request = value;}
}

public string FileName
{
get {return fileName;}
set {fileName = value;}
}
public Exception OperationException
{
get {return operationException;}
set {operationException = value;}
}
public string StatusDescription
{
get {return status;}
set {status = value;}
}
}
public class AsynchronousFtpUpLoader
{
// Command line arguments are two strings:
// 1. The url that is the name of the file being uploaded to the server.
// 2. The name of the file on the local machine.
//
public static void Main(string[] args)
{
// Create a Uri instance with the specified URI string.
// If the URI is not correctly formed, the Uri constructor
// will throw an exception.
ManualResetEvent waitObject;

Uri target = new Uri (args[0]);
string fileName = args[1];
FtpState state = new FtpState();
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(target);
request.Method = WebRequestMethods.Ftp.UploadFile;

// This example uses anonymous logon.
// The request is anonymous by default; the credential does not have to be specified.
// The example specifies the credential only to
// control how actions are logged on the server.

request.Credentials = new NetworkCredential ("anonymous","janeDoe@contoso.com");

// Store the request in the object that we pass into the
// asynchronous operations.
state.Request = request;
state.FileName = fileName;

// Get the event to wait on.
waitObject = state.OperationComplete;

// Asynchronously get the stream for the file contents.
request.BeginGetRequestStream(
new AsyncCallback (EndGetStreamCallback),
state
);

// Block the current thread until all operations are complete.
waitObject.WaitOne();

// The operations either completed or threw an exception.
if (state.OperationException != null)
{
throw state.OperationException;
}
else
{
Console.WriteLine("The operation completed - {0}", state.StatusDescription);
}
}
private static void EndGetStreamCallback(IAsyncResult ar)
{
FtpState state = (FtpState) ar.AsyncState;

Stream requestStream = null;
// End the asynchronous call to get the request stream.
try
{
requestStream = state.Request.EndGetRequestStream(ar);
// Copy the file contents to the request stream.
const int bufferLength = 2048;
byte[] buffer = new byte[bufferLength];
int count = 0;
int readBytes = 0;
FileStream stream = File.OpenRead(state.FileName);
do
{
readBytes = stream.Read(buffer, 0, bufferLength);
requestStream.Write(buffer, 0, readBytes);
count += readBytes;
}
while (readBytes != 0);
Console.WriteLine ("Writing {0} bytes to the stream.", count);
// IMPORTANT: Close the request stream before sending the request.
requestStream.Close();
// Asynchronously get the response to the upload request.
state.Request.BeginGetResponse(
new AsyncCallback (EndGetResponseCallback),
state
);
}
// Return exceptions to the main application thread.
catch (Exception e)
{
Console.WriteLine("Could not get the request stream.");
state.OperationException = e;
state.OperationComplete.Set();
return;
}

}

// The EndGetResponseCallback method
// completes a call to BeginGetResponse.
private static void EndGetResponseCallback(IAsyncResult ar)
{
FtpState state = (FtpState) ar.AsyncState;
FtpWebResponse response = null;
try
{
response = (FtpWebResponse) state.Request.EndGetResponse(ar);
response.Close();
state.StatusDescription = response.StatusDescription;
// Signal the main application thread that
// the operation is complete.
state.OperationComplete.Set();
}
// Return exceptions to the main application thread.
catch (Exception e)
{
Console.WriteLine ("Error getting response.");
state.OperationException = e;
state.OperationComplete.Set();
}
}
}
}





Hope this helps,

Edo

PS: If you bought a professional windows package for domain 'www.yourdomain.com', It's standard that you can upload your files (for your website and for other uses) by just typing 'ftp.yourdomain.com/uploaddir'. Of course you have to create an uploaddir first.

Share this post


Link to post
Share on other sites
I am still confused about what you want done.
okay, so you paid network solutions to host your domain?
Then they must've gave you an ftp address right?
and a login ID and password to upload your stuff?

Share this post


Link to post
Share on other sites

This topic is 4268 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this