0

Hi Guys,

I am attempting to write an application that copies any file from the user's local machine to another server on the same network.

The Catch

The server that will house the application is separate from the server that will receive the files from the local user's machine. In other words, to do the file copy the user will have to access the application on one server via IIS and within the application it must place that file on another server. Further, these servers while on the same network cannot physically see each other.

If anyone has anythoughts on how to accomplish this i would be grateful.

2
Contributors
2
Replies
22
Views
4 Years
Discussion Span
Last Post by GTTravis
0

As I was reading, I was going to recommend that you create a virtual directory on the web server, but then I read ---

Further, these servers while on the same network cannot physically see each other.

If the web server cannot see the target file server, I dont see how you can integrate the web server into this solution. This sounds like a client side app instead that can initiate more than one connection..??

Edited by JorgeM

0

I did some research and used FTP however i have an issue.

The files are transferred successfully if i run my application from my system. when the application is placed in IIS7 it transfers the files however the files arrive on the server empty.

i am attaching the code that actually does the upload from a local user system to the file server.

public bool upload(string remoteFile, string localFile)
{
    bool statval = true;
    try
    {
        /* Create an FTP Request
      */
        FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(remoteFile);
        ftpRequest.UseBinary = true;
        /* Log in to the FTP Server with the User Name and Password Provided */
        ftpRequest.Credentials = new NetworkCredential(_username, _password);
        /* When in doubt, use these options */
        ftpRequest.UseBinary = true;
        //ftpRequest.Proxy = null;
        //ftpRequest.UsePassive = true;
        //ftpRequest.KeepAlive = true;
        /* Specify the Type of FTP Request */
        ftpRequest.Method = WebRequestMethods.Ftp.UploadFile;
        /* Establish Return Communication with the FTP Server */
        Stream ftpStream = ftpRequest.GetRequestStream();

        /* Open a File Stream to Read the File for Upload */
        FileStream localFileStream = new FileStream(localFile, FileMode.Open);
        /* Buffer for the Downloaded Data */
        byte[] byteBuffer = new byte[bufferSize];
        int bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
        /* Upload the File by Sending the Buffered Data Until the Transfer is Complete */
        try
        {
            while (bytesSent != 0)
            {
                ftpStream.Write(byteBuffer, 0, bytesSent);
                bytesSent = localFileStream.Read(byteBuffer, 0, bufferSize);
            }
        }
        catch (Exception ex)
        {
            // Console.WriteLine(ex.ToString());
            statval = false;
        }
        /* Resource Cleanup */
        localFileStream.Close();
        ftpStream.Close();
        ftpRequest = null;
    }
    catch (Exception ex)
    {
        //Console.WriteLine(ex.ToString()); 
        statval = false;
    }
    return statval;
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.